<p><code>new line detected</code> should give you an idea of what to look for - your macro file may have some line breaks between code blocks, and it's writing them to the page before hitting your redirect tag. Try wrapping it all in <code>{% spaceless %}</code> tags, and see if that helps?</p>

CC BY-SA 4.0
2021-07-13T03:46:22.093Z
Here's some info on whitespace control in Twig: https://symfony.com/blog/better-white-space-control-in-twig-templates and https://twig.symfony.com/doc/2.x/templates.html#templates-whitespace-control
michaelroper
CC BY-SA 4.0
2021-07-13T03:47:47.273Z
Yep, that did it! Thanks :)
Tyssen
CC BY-SA 4.0
2021-07-13T03:37:28.383Z
2021-07-13T03:37:28.383Z
michaelroper
<p>I have this in a template:</p>
<pre><code>{% import &quot;_helpers/macros&quot; as macros %}
{% set redirectUrl = macros.testRelatedReview(entry) %}
{% redirect redirectUrl 301 %}
</code></pre>
<p>The macro returns an entry URL.</p>
<p>But the page returns an error:</p>
<blockquote>
<p>Header may not contain more than a single header, new line detected</p>
</blockquote>
<p>If I change it to <code>{% redirect 'actual_value_of_redirectUrl' 301 %}</code>, it redirects OK.</p>
<p>How do I get it to work with the dynamic variable though?</p>

<redirect>
Header may not contain more than a single header, new line detected error with `redirect` tag
# Header may not contain more than a single header, new line detected error with `redirect` tag

(Asked by: username_0 on 2021-07-13)

I have this in a template:
{% import "_helpers/macros" as macros %}
{% set redirectUrl = macros.testRelatedReview(entry) %}
{% redirect redirectUrl 301 %}

The macro returns an entry URL.
But the page returns an error:

Header may not contain more than a single header, new line detected

If I change it to {% redirect 'actual_value_of_redirectUrl' 301 %}, it redirects OK.
How do I get it to work with the dynamic variable though?

**Tags:** redirect

---

## 1 answers

### Answer by username_1 on 2021-07-13. Score: 2 | Accepted answer

`new line detected` should give you an idea of what to look for - your macro file may have some line breaks between code blocks, and it's writing them to the page before hitting your redirect tag. Try wrapping it all in `{% spaceless %}` tags, and see if that helps?

> **Comments:**
> **username_1**: Here's some info on whitespace control in Twig: https://symfony.com/blog/better-white-space-control-in-twig-templates and https://twig.symfony.com/doc/2.x/templates.html#templates-whitespace-control  
> **username_0**: Yep, that did it! Thanks :)  

---

