<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>

CC BY-SA 3.0
2017-11-01T20:14:44.223Z
2017-11-01T20:21:55.520Z
2017-11-01T20:21:55.520Z
Damon
<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>

CC BY-SA 3.0
2017-11-01T21:21:14.057Z
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
Robin Schambach
<templating><variable>
How can I access a template variable from an include that is loaded via ajax?
# 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 %}   
    ...
    
    ...
{% 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

    
        My Project
        
        
            {# image will go here. #}
        
        
            My Project Description
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eros dolor, efficitur lobortis eros et, dictum hendrerit nulla.
            Client: My Client
        
    



What I would like to do is:
...
{{ project.title }}

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 %}
...
{{ project.title }}


---

