Answers.Body: <p>Since you are only trying to access the existing entry model, you should be able to do something like this:</p>
  
  <p><strong>portfolio/_entry.twig</strong></p>
  
  <pre><code>{% set project = entry %}
  ...
  &lt;h1&gt;{{ project.title }}&lt;/h1&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-01T20:14:44.223Z
Answers.LastActivityDate: 2017-11-01T20:21:55.520Z
Answers.LastEditDate: 2017-11-01T20:21:55.520Z
Answers.UserDisplayName: Damon
Body: <p>I am making an ajax request to an entry. It is returning the entry's html - and all is working great.</p>
  
  <p>I have a section called "portfolio" and I loop through each:</p>
  
  <p><strong>portfolio/index.twig</strong></p>
  
  <pre><code>{% set projects = craft.entries.section('portfolio') %}
  ...
  {% for project in projects %}   
      ...
      &lt;a href="#!{{ project.slug }}" class="hover-overlay"&gt;
      ...
  {% endfor %}
  </code></pre>
  
  <p>When the project is clicked, I am making an ajax request to an entry. It is returning the entry's html - and all is working great.</p>
  
  <p>Now I would like to strip out the <em>static</em> html, and access the parent's entry variable.</p>
  
  <p>For example, here is the html that I am returning.</p>
  
  <p><strong>portfolio/_entry.twig</strong></p>
  
  <pre><code>&lt;div class="item-content"&gt;
      &lt;div class="container"&gt;
          &lt;h3&gt;My Project&lt;/h3&gt;
          &lt;div class="row"&gt;
          &lt;div class="col-md-9"&gt;
              {# image will go here. #}
          &lt;/div&gt;
          &lt;div class="col-md-3"&gt;
              &lt;h4&gt;My Project Description&lt;/h4&gt;
              &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eros dolor, efficitur lobortis eros et, dictum hendrerit nulla.&lt;/p&gt;
              &lt;p&gt;Client: My Client&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>What I would like to do is:</p>
  
  <pre><code>...
  &lt;h3&gt;{{ project.title }}&lt;/h3&gt;
  </code></pre>
  
  <p>I'm not sure how to do is something like this from within <code>portfolio/_entry.twig</code></p>
  
  <pre><code>{% set project = ?? %}
  </code></pre>
  
  <p>So that I <em>can</em> use <code>{{ project.title }}</code></p>
  
  <p>Thank you for any suggestions!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-01T21:21:14.057Z
Comments.Text: You know you can pass variables into templates you render in your controller. So you can just send the ID of your project with your ajax request (or the slug) and fetch the project by id (or slug) in your controller, then you pass it into the template. Your 2. Parameter of `renderTemplate` is an array of all variables you like to access in your template. I'm not sure where the problem is
Comments.UserDisplayName: Robin Schambach
Tags: <templating><variable>
Title: How can I access a template variable from an include that is loaded via ajax?
ThreadText: # How can I access a template variable from an include that is loaded via ajax?
  
  (Asked by: username_0 on 2017-11-01)
  
  I am making an ajax request to an entry. It is returning the entry's html - and all is working great.
  
  I have a section called "portfolio" and I loop through each:
  
  **portfolio/index.twig**
  
  ```
  {% set projects = craft.entries.section('portfolio') %}
  ...
  {% for project in projects %}   
      ...
      <a href="#!{{ project.slug }}" class="hover-overlay">
      ...
  {% endfor %}
  
  ```
  
  When the project is clicked, I am making an ajax request to an entry. It is returning the entry's html - and all is working great.
  
  Now I would like to strip out the *static* html, and access the parent's entry variable.
  
  For example, here is the html that I am returning.
  
  **portfolio/\_entry.twig**
  
  ```
  <div class="item-content">
      <div class="container">
          <h3>My Project</h3>
          <div class="row">
          <div class="col-md-9">
              {# image will go here. #}
          </div>
          <div class="col-md-3">
              <h4>My Project Description</h4>
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eros dolor, efficitur lobortis eros et, dictum hendrerit nulla.</p>
              <p>Client: My Client</p>
          </div>
      </div>
  </div>
  
  ```
  
  What I would like to do is:
  
  ```
  ...
  <h3>{{ project.title }}</h3>
  
  ```
  
  I'm not sure how to do is something like this from within `portfolio/_entry.twig`
  
  ```
  {% set project = ?? %}
  
  ```
  
  So that I *can* use `{{ project.title }}`
  
  Thank you for any suggestions!
  
  **Tags:** templating, variable
  
  > **Comments:**
  > **username_1**: You know you can pass variables into templates you render in your controller. So you can just send the ID of your project with your ajax request (or the slug) and fetch the project by id (or slug) in your controller, then you pass it into the template. Your 2. Parameter of `renderTemplate` is an array of all variables you like to access in your template. I'm not sure where the problem is  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-11-01. Score: 1 | Accepted answer
  
  Since you are only trying to access the existing entry model, you should be able to do something like this:
  
  **portfolio/\_entry.twig**
  
  ```
  {% set project = entry %}
  ...
  <h1>{{ project.title }}</h1>
  
  ```
  
  
  ---
  
  