0

I have created a twig file in sonata admin, where I want to show the preview of the another twig created using the sonata cms.

I found the use of render method to embed the controller action.

<div class="preview">
                        {{ render(controller('Bundle:Controller:action') }}
</div>

But the action takes an argument $contentDocument

public function Action($contentDocument, Request $request)
{
}

So how do I render this twig inside the preview div, to show a thumbnail to the user. Thank you

Satya S
  • 228
  • 1
  • 6

1 Answers1

1

You can pass parameters as a second parameter to the controller() twig function: {{ render(controller('Bundle:Controller:action', {'contentDocument': some_instance_of_a_content_document}) }}

  • I tried that, the problem is how can I get the handle of the instance of the content document in the twig? Any suggestions? – Satya S Sep 26 '14 at 08:10
  • 1
    You can fetch a document from the repository inside twig. the relevant methods are part of the CoreBundle: http://symfony.com/doc/master/cmf/bundles/core/templating.html – Lukas Kahwe Smith Sep 26 '14 at 11:07
  • note that if you intend to use the render(controller()) for ESI, there will be a sub request and you can't share the request context (and also can't pass objects, only scalar values). then you would need to pass the *id* of that content document and load it in the controller. – dbu Sep 29 '14 at 06:33