<p dir="auto">This is a small new feature/improvement.<br>
If you have in parameters.yml a parameter as Array :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="database:
    blog:
        host: blog-host
        name: blog-name
    store:
        host: store-host
        name: store-name"><pre class="notranslate"><code class="notranslate">database:
    blog:
        host: blog-host
        name: blog-name
    store:
        host: store-host
        name: store-name
</code></pre></div>
<p dir="auto">You can retrieve the parameter from a container</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$container-&gt;getParameter('database');"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>container</span>-&gt;<span class="pl-en">getParameter</span>(<span class="pl-s">'database'</span>);</pre></div>
<p dir="auto">However, there is no way to use that parameter from a config.yml definition, for instance (as an example) this parameter is not usuable to feed a doctrine connection.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="doctrine:
    dbal:
        connections:
            blog:
                driver:   %database_driver%
                host:     %database[blog][host]% #Doesn't work
                port:     %database_port%
                dbname:   %database[blog][name]% #Doesn't work
            store:
                driver:   %database_driver%
                host:     %database[store][host]% #Doesn't work
                port:     %database_port%
                dbname:   %database[store][name]% #Doesn't work"><pre class="notranslate"><code class="notranslate">doctrine:
    dbal:
        connections:
            blog:
                driver:   %database_driver%
                host:     %database[blog][host]% #Doesn't work
                port:     %database_port%
                dbname:   %database[blog][name]% #Doesn't work
            store:
                driver:   %database_driver%
                host:     %database[store][host]% #Doesn't work
                port:     %database_port%
                dbname:   %database[store][name]% #Doesn't work
</code></pre></div>
<p dir="auto">Some people were looking for this feature on stackoverflow<br>
<a href="http://stackoverflow.com/questions/19919679/symfony2-how-to-read-parameters-array-in-config-yml" rel="nofollow">http://stackoverflow.com/questions/19919679/symfony2-how-to-read-parameters-array-in-config-yml</a></p>
<p dir="auto">Currently an optional variable (that has a default and can be left out from matching and generating URLs) can only be specified without any text suffix, i.e. at the end of the pattern. This is quite limiting.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/laszlokorte/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/laszlokorte">@laszlokorte</a> and I propose to add the possibility to mark the optional parts with parentheses/curly brackets.<br>
This can be implemented BC and would allow several new, but common use-cases, e.g.:</p>
<ul dir="auto">
<li>one can specify optional variables anywhere in the pattern (not only at the end),</li>
<li>one can use more than one char as seperator,</li>
<li>an optional part that depends on multiple variables,</li>
<li>flexiblity of where, what and whether there is a (trailing) seperator (see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="8132275" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/5918" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/5918/hovercard" href="https://github.com/symfony/symfony/issues/5918">#5918</a>).</li>
</ul>
<p dir="auto">Examples:</p>
<ul dir="auto">
<li><code class="notranslate">/products(-by-{criterion}).html</code> would either match <code class="notranslate">/products.html</code> with <code class="notranslate">criterion = default</code> or <code class="notranslate">/products-by-price.html</code> with <code class="notranslate">criterion = 'price'</code></li>
<li><code class="notranslate">/products(/{category}(.{_format}))</code> would be equivalent to how we already handle <code class="notranslate">/products/{category}.{_format}</code> with defaults for both variables. It matches <code class="notranslate">/products</code>, <code class="notranslate">/products/shoes</code> and <code class="notranslate">/products/shoes.html</code>. But it does not match <code class="notranslate">/products.html</code>! Compare that to</li>
<li><code class="notranslate">/products((/{category}).{_format})</code> (only brackets changed) where the format would match without category, but the category does not match without the format. So the inner part requires the outer part to match.</li>
<li><code class="notranslate">/products(-in-{category})(-by-{criterion}).html</code> matches <code class="notranslate">/products.html</code> and <code class="notranslate">/products-in-shoes-by-prize.html</code> and <code class="notranslate">/products-in-shoes.html</code> and <code class="notranslate">/products-by-prize.html</code>.</li>
<li><code class="notranslate">/products(-in-{category1}-and-{category2}).html</code> only matches the optional part when both variables match, so <code class="notranslate">/products-in-shoes-and-suits.html</code> and <code class="notranslate">/products.html</code>, but not <code class="notranslate">/products-in-shoes.html</code>.</li>
<li><code class="notranslate">/products(-by-price).html</code> should either raise exception that there is no variable in it, or treat it as-is (with the parentheses). It must not match both <code class="notranslate">/products.html</code> and <code class="notranslate">/products-by-prize.html</code> (where you should usually specify 2 routes for it) because there would be no way to decide which URL to generate.</li>
<li><code class="notranslate">/products/({category})</code> would match <code class="notranslate">/products/</code> and <code class="notranslate">/products/...</code> whereas without the parentheses it would match <code class="notranslate">/products</code> and <code class="notranslate">/products/...</code> (see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="7955938" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/5869" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/5869/hovercard" href="https://github.com/symfony/symfony/issues/5869">#5869</a>)</li>
<li><code class="notranslate">/{product}((-by-{criterion}).{_format})</code> would need a default requirement for <code class="notranslate">product</code> to be <code class="notranslate">[^/-\.]++</code> (so as seperator both <code class="notranslate">/</code> (standard) and <code class="notranslate">-</code> and <code class="notranslate">.</code>.  Pretty hard to compile.</li>
</ul>
<p dir="auto">Also, it should raise an exception when you specify an optional part explicitly without adding a default for the variable in it.</p>
<p dir="auto">This feature request is somewhat related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5949354" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/5129" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/5129/hovercard" href="https://github.com/symfony/symfony/pull/5129">#5129</a> and also covers <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="7955938" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/5869" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/5869/hovercard" href="https://github.com/symfony/symfony/issues/5869">#5869</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="27201048" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/10217" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/10217/hovercard" href="https://github.com/symfony/symfony/issues/10217">#10217</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25308687" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/9981" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/9981/hovercard" href="https://github.com/symfony/symfony/issues/9981">#9981</a></p>