0

I have a list.html.twig file in which I have included another template file like:

<div class="panel-body">
    {{ include('default/partials/groupSettings.html.twig') }}
</div>

And in my controller function following is given:

public function settingsListAction()
{
    $settingsGroup = $this->getDoctrine()->getRepository('AppBundle:J1SettingGroup')->findAll();

    return $this->render('default/settingsList.html.twig', array('settingsGroup' => $settingsGroup));

    $settingsList = $this->getDoctrine()->getRepository('AppBundle:J1Setting')->findAll();

    return $this->render('default/partials/groupSettings.html.twig', array('settingsList' => $settingsList));
}

But it only loading the first template and not the second.

1 Answer 1

1

includes should be written like so :

{{ include('[BundleName]:[directory_with_your_template]:templatename.html.twig', { 'settingsGroup': settingsGroup }) }}

and in your controller you render only the parent template and pass the params you need to the child template

public function settingsListAction()
{
    $settingsGroup = $this->getDoctrine()->getRepository('AppBundle:J1SettingGroup')->findAll();
    $settingsList = $this->getDoctrine()->getRepository('AppBundle:J1Setting')->findAll();

    return $this->render('default/settingsList.html.twig', array('settingsGroup' => $settingsGroup, 'settingsList' => $settingsList));
}
Sign up to request clarification or add additional context in comments.

3 Comments

{{ include('[AppBundle]:[default/partials]:templatename.html.twig', { 'settingsGroup': settingsGroup }) }} Is it correct?
remove the square brackets "[ ]"
Bundle:Subdir:filename.html.twig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.