简体   繁体   中英

Add a Custom link in Listing Screen Sonata Admin Bundle

I am using sonata admin bundle. I have a company table and a product table. Each company can have many products. I am displaying the company table. What I want is that against each row of the company table, I need to place a link and when clicked it goes to the related product table. I am able to figure out how to show the related products. But I could not find out how to place a link along with each row of the company. Please help me on this. I googled and could find posts on how to place custom link in the dashboard which is not I need. Any help would be greatly appreciated. Thanks

You have to generate a new template which does the job.

After that you have to set something like this at your listMapper config:

->add('yourLink', null, array('template' => '::testfield.html.twig'))

Look into the SonataAdminBundle:Resource/CRUD/ folder where all list templates located.

For a string the *base_list_field.html.twig* gets rendered.

I figured it out myself. You need to create a custom template and then add it as an action.

->add('_action', 'actions', array(
            'actions' => array(
                'floorplan' => array('template' => 'YourBundle:testLink.html.twig'),
            )
        ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM