<p dir="auto">It would be useful if the route generator could filter by certain route criteria, especially "host".</p>
<p dir="auto"><em>(Sorry, I already posted in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="8572536" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/6088" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/6088/hovercard" href="https://github.com/symfony/symfony/issues/6088">#6088</a> but that issue is already closed, and the request was for a different use case.)</em></p>
<p dir="auto">Here is a possible use case for a generator that filters by host, please feel free to point out an alternative approach though. In short, I want to be able to do something like this in Twig:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{{ path('contact') }}"><pre class="notranslate"><code class="notranslate">{{ path('contact') }}
</code></pre></div>
<p dir="auto">and get the right route depending on the current hostname (but other applications might have other criteria).</p>
<p dir="auto">Let's say I have English and German versions of a site, under different domains: example.co.uk and example.de. Then, I can import groups of routes like this:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    uk_routes:
        resource: @MyBundle/Resources/config/routing_uk.yml
        host: &quot;example.co.uk&quot;

    de_routes:
        resource: @MyBundle/Resources/config/routing_de.yml
        host: &quot;example.de&quot;"><pre class="notranslate">    <span class="pl-ent">uk_routes</span>:
        <span class="pl-ent">resource</span>: <span class="pl-s">@MyBundle/Resources/config/routing_uk.yml</span>
        <span class="pl-ent">host</span>: <span class="pl-s"><span class="pl-pds">"</span>example.co.uk<span class="pl-pds">"</span></span>

    <span class="pl-ent">de_routes</span>:
        <span class="pl-ent">resource</span>: <span class="pl-s">@MyBundle/Resources/config/routing_de.yml</span>
        <span class="pl-ent">host</span>: <span class="pl-s"><span class="pl-pds">"</span>example.de<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">Then, in each file, I might try something like this:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    # routing_uk.yml
    contact:
        path: /contact
        defaults:
            _controller: my_site.controller.default:contactAction

    # routing_de.yml
    contact:
        path: /kontakt
        defaults:
            _controller: my_site.controller.default:contactAction"><pre class="notranslate">    <span class="pl-c"><span class="pl-c">#</span> routing_uk.yml</span>
    <span class="pl-ent">contact</span>:
        <span class="pl-ent">path</span>: <span class="pl-s">/contact</span>
        <span class="pl-ent">defaults</span>:
            <span class="pl-ent">_controller</span>: <span class="pl-s">my_site.controller.default:contactAction</span>

    <span class="pl-c"><span class="pl-c">#</span> routing_de.yml</span>
    <span class="pl-ent">contact</span>:
        <span class="pl-ent">path</span>: <span class="pl-s">/kontakt</span>
        <span class="pl-ent">defaults</span>:
            <span class="pl-ent">_controller</span>: <span class="pl-s">my_site.controller.default:contactAction</span></pre></div>
<p dir="auto"><em>But...</em> this won't work, because one "contact" route silently overwrite the other.</p>
<p dir="auto">An "alias" (or "forward") parameter would help here:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    # routing_uk.yml
    uk_contact:
        alias: contact
        path: /contact
        defaults:
            _controller: my_site.controller.default:contactAction
        options:
            foo: bar_uk_example

    # routing_de.yml
    de_contact:
        alias: contact
        path: /uber_uns
        defaults:
            _controller: my_site.controller.default:contactAction
        options:
            foo: bar_de_example"><pre class="notranslate">    <span class="pl-c"><span class="pl-c">#</span> routing_uk.yml</span>
    <span class="pl-ent">uk_contact</span>:
        <span class="pl-ent">alias</span>: <span class="pl-s">contact</span>
        <span class="pl-ent">path</span>: <span class="pl-s">/contact</span>
        <span class="pl-ent">defaults</span>:
            <span class="pl-ent">_controller</span>: <span class="pl-s">my_site.controller.default:contactAction</span>
        <span class="pl-ent">options</span>:
            <span class="pl-ent">foo</span>: <span class="pl-s">bar_uk_example</span>

    <span class="pl-c"><span class="pl-c">#</span> routing_de.yml</span>
    <span class="pl-ent">de_contact</span>:
        <span class="pl-ent">alias</span>: <span class="pl-s">contact</span>
        <span class="pl-ent">path</span>: <span class="pl-s">/uber_uns</span>
        <span class="pl-ent">defaults</span>:
            <span class="pl-ent">_controller</span>: <span class="pl-s">my_site.controller.default:contactAction</span>
        <span class="pl-ent">options</span>:
            <span class="pl-ent">foo</span>: <span class="pl-s">bar_de_example</span></pre></div>
<p dir="auto">If only one route had the "contact" alias, it's easy for the Generator to know which route to use (we could even just duplicate the route behind the scenes, to save a copy and paste).</p>
<p dir="auto">But here, the routing generator is faced with two different routes with the same alias. So it needs to decide which one to pick. In this case, I want it to filter on the <code class="notranslate">host</code> (each route has this, but I defined it at the file level instead of each route). Maybe there are other things to filter on too, so it should be configurable/extensible.</p>
<p dir="auto">For now, I have created a <a href="https://github.com/fazy/FazyMultiSiteBundle/blob/master/Routing/Generator/UrlGenerator.php">very basic route generator</a> that does this. It's part of a very rough/experimental bundle that should probably be split apart, but hopefully it gives an idea.</p>
<p dir="auto">Of course, I could be looking at this the wrong way. Maybe we don't need route aliases, but namespaces? Or multiple routers (but then, how to select which one is being used?)</p>
<p dir="auto">I also started a <a href="https://groups.google.com/forum/#!topic/symfony2/tUEmPDbyoKw" rel="nofollow">mailing list topic</a> about this. I'm interested to know the best approach, how other people satisfy this use case, and whether a future Symfony route generator can allow allow multiple route candidates (aliases, or similar).</p>
<p dir="auto">When Symfony2 was launched in the summer of 2011, Twig was a relatively new project and thus, Symfony decided to support both Twig and PHP templates. Now it's clear that Twig is the way to go when developing Symfony applications and it's getting better and better with each new version.</p>
<p dir="auto">That's why <strong>I'd like to propose to drop PHP templates support entirely for Symfony 3.0</strong>.</p>
<p dir="auto">Pros:</p>
<ul dir="auto">
<li>Much less code to maintain, specially on heavy components such as forms.</li>
<li>Much less documentation to write or maintain. We could use those resources to create new docs or improve the existing ones.</li>
<li>Ideally, if we only define one default templating format, we could also optimize Symfony performance and configuration .</li>
</ul>
<p dir="auto">Cons:</p>
<ul dir="auto">
<li>The tiny fraction of developers still using PHP templates will have to configure <em>something</em> or install <em>something</em> to be able to use PHP templates.</li>
</ul>