1

I'd like to retrieve the name of a section based on a url segment. Normally I would use {{entry.section.name}}, but this doesn't work, since there is no entry available.

I've got this working:

{% set entry = craft.entries.section(craft.request.getSegment(1)).first %}

<h2>{{entry.section.name}}</h2>

This means that I first have to get an entry and then reverse retrieve the section it belongs to.

Is there no direct way to get the section name based on a url?

1 Answer 1

3

Do you mean

{% set section = craft.sections.getSectionByHandle(craft.request.getSegment(1)) %}
{{ section.name }}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.