Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-13T03:46:22.093Z
Answers.Text: 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
Answers.UserDisplayName: michaelroper
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-13T03:47:47.273Z
Answers.Text: Yep, that did it! Thanks :)
Answers.UserDisplayName: Tyssen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-13T03:37:28.383Z
Answers.LastActivityDate: 2021-07-13T03:37:28.383Z
Answers.UserDisplayName: michaelroper
Body: <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>
  
Tags: <redirect>
Title: Header may not contain more than a single header, new line detected error with `redirect` tag
ThreadText: # 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 :)  
  
  ---
  
  