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

CC BY-SA 3.0
2016-08-27T20:01:23.797Z
That works but it's outputting "8" for august rather than "08" how would I get the leading zero?
CreateSean
CC BY-SA 3.0
2016-08-27T20:03:26.690Z
found it:  ~ now|date("m")
CreateSean
CC BY-SA 3.0
2016-08-27T18:45:03.093Z
2016-08-27T18:45:03.093Z
carlcs
<p>I've got a calendar template set up and would like to have <a href="http://domain.com/calendar" rel="nofollow">http://domain.com/calendar</a> redirect to <a href="http://domain.com/calendar/current_year/current_month" rel="nofollow">http://domain.com/calendar/current_year/current_month</a> but am having trouble getting this to work.</p>

<p>My current code is:</p>

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

<p>But this ends up going to a 404 with this url:
<a href="http://domain.com/calendar/%7B%7B%20now.year%20%7D%7D/%7B%20now.month%20%7D/" rel="nofollow">http://domain.com/calendar/%7B%7B%20now.year%20%7D%7D/%7B%20now.month%20%7D/</a></p>

<templating><redirect>
Redirect to url based on current year/month
# Redirect to url based on current year/month

(Asked by: username_0 on 2016-08-27)

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/

**Tags:** templating, redirect


---

## 1 answers

### Answer by username_1 on 2016-08-27. Score: 2 | Accepted answer

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 %}`

> **Comments:**
> **username_0**: That works but it's outputting "8" for august rather than "08" how would I get the leading zero?  
> **username_0**: found it:  ~ now|date("m")  

---

