2

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 %}
    <li>
        <a href="{{ section.handle }}{{ url('types/'~entryType.handle) }}">
            {{ entryType.name|ucfirst }}
        </a>
    </li>
{% 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.

Dominik Krulak
  • 1,562
  • 14
  • 27

1 Answers1

5

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:

<a href="{{ url(section.handle ~ '/types/' ~ entryType.handle) }}">

-or-

<a href="{{ siteUrl ~ section.handle ~ '/types/' ~ entryType.handle }}">

Aaron Berkowitz
  • 3,819
  • 10
  • 20
  • Have tried it before. And with the same effect. I keep looking for the root of a problem. – Dominik Krulak Apr 13 '15 at 07:43
  • Well, just after I posted my last comment, I think I've fixed it. I don't know, if it's correct, but it seems to be working. <a href="{{ url(section.handle ~ '/types/' ~ entryType.handle) }}">{{ entryType.name|ucfirst }}</a> ? – Dominik Krulak Apr 13 '15 at 07:46
  • That should work! I updated my answer to include your solution and another using siteUrl – Aaron Berkowitz Apr 13 '15 at 19:24