0

I've got a calendar template set up and would like to have http://domain.com/calendar redirect to http://domain.com/calendar/current_year/current_month but am having trouble getting this to work.

My current code is:

{% if craft.request.segment(2) == "" %}
  {% redirect "calendar/{{ now.year }}/{{ now.month }}" %}
{% endif %}

But this ends up going to a 404 with this url: http://domain.com/calendar/%7B%7B%20now.year%20%7D%7D/%7B%20now.month%20%7D/

2

You never use {{ echo tags within other Twig tags. What you have to do instead is to use string concatenation.
{% redirect "calendar/" ~ now.year ~ "/" ~ now.month %}

| improve this answer | |
  • That works but it's outputting "8" for august rather than "08" how would I get the leading zero? – CreateSean Aug 27 '16 at 20:01
  • found it: ~ now|date("m") – CreateSean Aug 27 '16 at 20:03

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.