<p>Update line 5 to <strong>concatenate</strong> the path/URL with the variable <strong>workTitle</strong>.</p>

<p><code>{% redirect "/visit/index?artwork=" ~ workTitle %}</code></p>

CC BY-SA 3.0
2018-02-04T23:58:24.150Z
FWIW: You can also interpolate the variable, like this: `{% redirect "/visit/index?artwork=#{workTitle}" %}`. This syntax might be preferable if you have many variables to include in the query params.
August Miller
CC BY-SA 3.0
2018-02-05T00:00:47.347Z
Also… the `url` Twig helper might come in handy! `{% redirect url('/visit/index', { artwork: workTitle }) %}`. The added benefit here is that it discards null values, and keeps your URLs nice and trim.
August Miller
CC BY-SA 3.0
2017-04-10T06:22:30.010Z
2017-04-10T06:32:58.020Z
2017-04-10T06:32:58.020Z
Selvin Ortiz
<p>I think:</p>

<pre><code>{% redirect "/visit/index?artwork="~workTitle %}
</code></pre>

CC BY-SA 3.0
2017-04-10T06:26:11.350Z
Beat me to it
Selvin Ortiz
CC BY-SA 3.0
2017-04-10T06:30:54.407Z
Apparently not. @SelvinOrtiz I think you had me by 3-4 seconds. Might want to add the initial "{" to your code.
AbbeyDesign
CC BY-SA 3.0
2017-04-10T06:32:51.967Z
And you took the time to explain what you were doing, mine was a limp "I think". Sad.
AbbeyDesign
CC BY-SA 3.0
2017-04-10T06:22:42.777Z
2017-04-10T06:22:42.777Z
AbbeyDesign
<pre><code>1.{% set workTitle = craft.request.getLastSegment()  %}
2.{% if currentUser %}
3.     {{workTitle}}
4.{% else %}
5.  {% redirect "/visit/index?artwork=workTitle" %}
6.{% endif %}
</code></pre>

<p>Each line of code are working fine except the line 5. I set a value on line 1. Line 3 returns the set value but on line 5 when am trying to redirect it doesn't return correct path.
Redirect returns the below path instead of the returning the set value of workTitle.</p>

<p><strong><a href="http://abc.dev/visit/index?artwork=workTitle" rel="nofollow noreferrer">http://abc.dev/visit/index?artwork=workTitle</a></strong></p>

<templating><redirect>
how can pass a variable in redirect?
# how can pass a variable in redirect?

(Asked by: username_0 on 2017-04-10)

1.{% set workTitle = craft.request.getLastSegment()  %}
2.{% if currentUser %}
3.     {{workTitle}}
4.{% else %}
5.  {% redirect "/visit/index?artwork=workTitle" %}
6.{% endif %}

Each line of code are working fine except the line 5. I set a value on line 1. Line 3 returns the set value but on line 5 when am trying to redirect it doesn't return correct path.
Redirect returns the below path instead of the returning the set value of workTitle.
http://abc.dev/visit/index?artwork=workTitle

**Tags:** templating, redirect


---

## 2 answers

### Answer by username_3 on 2017-04-10. Score: 6 | Accepted answer

I think:
{% redirect "/visit/index?artwork="~workTitle %}

> **Comments:**
> **username_1**: Beat me to it  
> **username_3**: Apparently not. @SelvinOrtiz I think you had me by 3-4 seconds. Might want to add the initial "{" to your code.  
> **username_3**: And you took the time to explain what you were doing, mine was a limp "I think". Sad.  

---

### Answer by username_1 on 2017-04-10. Score: 5

Update line 5 to **concatenate** the path/URL with the variable **workTitle**.

`{% redirect "/visit/index?artwork=" ~ workTitle %}`

> **Comments:**
> **username_2**: FWIW: You can also interpolate the variable, like this: `{% redirect "/visit/index?artwork=#{workTitle}" %}`. This syntax might be preferable if you have many variables to include in the query params.  
> **username_2**: Also… the `url` Twig helper might come in handy! `{% redirect url('/visit/index', { artwork: workTitle }) %}`. The added benefit here is that it discards null values, and keeps your URLs nice and trim.  

---

