0

I've set up a structure channel that has entries at /services/slug however I want the /services template to redirect to the first entry in the services structure.

What I have now is:

{% for entry in craft.entries.section('services').limit(1) %}
  {% redirect '{{ entry.url }}' %}
{% endfor %}

However when visiting /services this redirects to a 404 page with url of /%7B%7B%20entry.url%20%7D%7D/

I also tried {% redirect "services/{{ entry.slug }}" %} but that didn't work either.

Is it possible to set up a redirect in the way that I am trying to do here?

8

You do not use the {{ }} inside other brackets you also should not use ' ' unless it is a specific string you want interpreted. Try instead:

{% for entry in craft.entries.section('services').limit(1) %}
     {% redirect entry.url %}
{% endfor %}

And you should be good to go

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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