0
votes

I have a problem with the following use case: I render a controller in a twig template where I have a navigation div with two links in it. In the middle of my page I have a div in which I would like to render the result of another controller. The decision which controllers twig should render is up to the click on the menu links. I hope the following code makes clear, what I mean:

{% extends 'base.html.twig' %}
{% block scripts %}
    {{ parent() }}
    <script type="text/javascript">
    $(function() {
        $( "#menu" ).menu();
      });
    </script>
    <style>
        .ui-menu {margin-bottom: 10px !important;}
    </style>
{% endblock %}
{% block stylesheets %}
    {{ parent() }}
    <link href="{{ asset('css/sstm_style.css') }}" rel="stylesheet" />
{% endblock %}

{% block body %}
{{ parent() }}
<div id="module_title"><h1>Lizenznehmer-Stammdaten</h1></div>
<nav>
    <h5>Was möchten Sie tun?</h5>
    <ul id="menu">
        <li><a href="#">Lizenznehmer anlegen</a></li>
        <li><a href="#">Lizenznehmer bearbeiten</a></li>
    </ul>
</nav>
<div id="main">
{# fill div with either CreateLicenseController or ChangeLicenseController #}
</div>
{% endblock %}

I know of the embed tag which renders a controller in a block of another controllers twig but I don't know how to tell twig at runtime which controller should be rendered

1

1 Answers

0
votes

You mean to generate controller by ajax request? Or you know which controller you need when rendering? If the last one, you can use if:

{% if needCreate %}
{{ render(controller('YourBundle:YourController:CreateLicenseController') }}
{% else %}
{{ render(controller('YourBundle:YourController:ChangeController') }}
{% endif %}

If you want load it by ajax, you shall make it in javascript, not in twig.