How do I build a link from variables? I'm building an entry type's menu, automatically populated with several sections. A route for dynamic menu had to be also created.

Code

{% set section = craft.sections.getSectionByHandle('sectionHandle') %}
{% set entryTypes = section.getEntryTypes() %}

{% for entryType in entryTypes %}
    &lt;li&gt;
        &lt;a href="{{ section.handle }}{{ url('types/'~entryType.handle) }}"&gt;
            {{ entryType.name|ucfirst }}
        &lt;/a&gt;
    &lt;/li&gt;
{% endfor %}


Output


craft.dev/sectionHandle/types/entryType.handle


When I access the link, It gets crazy.

Output


craft.dev/sectionHandle/types/sectionHandle/types/entryType.handle


I was trying everything I know, but Whatever I add in front of {{url('types/'~entryType.handle) }}, it gets duplicated.
Since you are building a custom URL, you shouldn't be using url() here, since it automatically appends your values to the siteUrl. Try one of these instead:

&lt;a href="{{ url(section.handle ~ '/types/' ~ entryType.handle) }}"&gt;

-or-

&lt;a href="{{ siteUrl ~ section.handle ~ '/types/' ~ entryType.handle }}"&gt;