Answers.Body: <p>Got this going by restructuring my templates. Not sure the exact reason I was getting the error but when I moved the variable declarations above the "extends" call the inner "include" had access to the variables. –</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T19:56:10.030Z
Answers.Text: A more detailed explanation of how to include with variables would be much appreciated. What was your solution? Can you share?
Answers.UserDisplayName: Vaughn D. Taylor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-11T22:27:26.517Z
Answers.Text: I wish I could tell you what I changed, but this was resolved just as I was getting the hand of twig/craft. I can say that I do use include with in my templates like this:{% set vars = {'title' : title } %}
   {% include "_includes/_header.html" with vars %}
Answers.UserDisplayName: Mosswalker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-18T18:35:26.483Z
Answers.LastActivityDate: 2017-12-18T18:35:26.483Z
Answers.UserDisplayName: Mosswalker
Answers.Body: <p>You're probably looking for:</p>
  
  <pre><code>{% include "singlepage" with { 'currentPage': 'leaders' } %}
  </code></pre>
  
  <p>The key (the part before the <code>:</code>) needs to be a string, hence in quotes.</p>
  
  <p>The relevant Twig template docs are here: <a href="https://twig.symfony.com/doc/2.x/tags/include.html#include" rel="nofollow noreferrer">https://twig.symfony.com/doc/2.x/tags/include.html#include</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-12T16:46:24.537Z
Answers.Text: No, that didn't do it. The singlepage template is still unaware of the currentPage variable. Could it be that singlepage is extending another template? Is it some kind of nesting issue? Any help appreciated. In the mean time, I'll go over the docs again.
Answers.UserDisplayName: Mosswalker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-15T22:27:13.833Z
Answers.Text: Got this going by restructuring my templates. Not sure the exact reason I was getting the error but when I moved the variable declarations above the "extends" call the inner "include" had access to the variables.
Answers.UserDisplayName: Mosswalker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-17T03:00:25.873Z
Answers.Text: Fair enough... would you mind adding that as an official answer in case it helps someone in the future?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-12T00:58:59.847Z
Answers.LastActivityDate: 2017-12-12T00:58:59.847Z
Answers.UserDisplayName: Brad Bell
Body: <p>New guy here. Can someone explain what the proper way to pass a variable into an include? I'm using this:</p>
  
  <pre><code>{% include "singlepage" with { currentPage:'leaders' } %}
  </code></pre>
  
  <p>.. and I'm getting a Variable "currentPage" does not exist error.</p>
  
  <p>In short, I have a template that I want to use for my singles pages, but I need to set a couple of variables for the template to use. So, I have a template for each single that simply sets the current page and then includes the single page template. Is this a good approach?</p>
  
  <p>Thanks for any help.</p>
  
Tags: <variable><include>
Title: Include with -- variable does not exist error
ThreadText: # Include with -- variable does not exist error
  
  (Asked by: username_0 on 2017-12-12)
  
  New guy here. Can someone explain what the proper way to pass a variable into an include? I'm using this:
  
  ```
  {% include "singlepage" with { currentPage:'leaders' } %}
  
  ```
  
  .. and I'm getting a Variable "currentPage" does not exist error.
  
  In short, I have a template that I want to use for my singles pages, but I need to set a couple of variables for the template to use. So, I have a template for each single that simply sets the current page and then includes the single page template. Is this a good approach?
  
  Thanks for any help.
  
  **Tags:** variable, include
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-12-18. Score: 0 | Accepted answer
  
  Got this going by restructuring my templates. Not sure the exact reason I was getting the error but when I moved the variable declarations above the "extends" call the inner "include" had access to the variables. –
  
  > **Comments:**
  > **username_1**: A more detailed explanation of how to include with variables would be much appreciated. What was your solution? Can you share?  
  > **username_0**: I wish I could tell you what I changed, but this was resolved just as I was getting the hand of twig/craft. I can say that I do use include with in my templates like this:{% set vars = {'title' : title } %}  {% include "_includes/_header.html" with vars %}  
  
  ---
  
  ### Answer by username_2 on 2017-12-12. Score: 2
  
  You're probably looking for:
  
  ```
  {% include "singlepage" with { 'currentPage': 'leaders' } %}
  
  ```
  
  The key (the part before the `:`) needs to be a string, hence in quotes.
  
  The relevant Twig template docs are here: <https://twig.symfony.com/doc/2.x/tags/include.html#include>
  
  > **Comments:**
  > **username_0**: No, that didn't do it. The singlepage template is still unaware of the currentPage variable. Could it be that singlepage is extending another template? Is it some kind of nesting issue? Any help appreciated. In the mean time, I'll go over the docs again.  
  > **username_0**: Got this going by restructuring my templates. Not sure the exact reason I was getting the error but when I moved the variable declarations above the "extends" call the inner "include" had access to the variables.  
  > **username_2**: Fair enough... would you mind adding that as an official answer in case it helps someone in the future?  
  
  ---
  
  