<p>Many thanks for your answers and apologies for the poor example in my question. Before your answers came in I continued researching and found the twig attribute function (<a href="http://twig.sensiolabs.org/doc/functions/attribute.html" rel="nofollow">http://twig.sensiolabs.org/doc/functions/attribute.html</a>). So I did this:</p>

<pre><code>{% for availability in craft.entries.section('availability2014').limit(52).find( {order: 'availabilityWeekBeginning asc'} ) %}
  {% set foo = attribute (availability, ['availability', craft.request.getSegment(2)|replace('-lake','')|capitalize]|join) %}

  {% for block in foo %}
      //Loop
  {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-06-22T17:10:13.920Z
Interesting, thanks for posting your solution!
Lindsey D
CC BY-SA 3.0
2014-06-22T17:03:09.430Z
2014-06-22T17:06:59.323Z
2014-06-22T17:06:59.323Z
user1070143
<p>Try this:</p>

<pre><code>{% for block in availability[foo] %}
</code></pre>

<p>The square brackets let you access a variable variable name on an object.</p>

<p>As a general rule you never put <code>{{ }}</code> inside of <code>{% %}</code> tags in twig.</p>

CC BY-SA 3.0
2014-06-22T16:49:26.693Z
2014-06-22T22:27:36.020Z
2014-06-22T22:27:36.020Z
Keith Mancuso
<p>Twig isn't like ExpressionEngine, there is no "parse order" to contend with. In Twig, you <strong>cannot nest tags within other tags</strong>.</p>

<p>So that line of code should look more like this:</p>

<pre><code>{% for block in availability.foo %}
</code></pre>

<p>... or even this:</p>

<pre><code>{% for block in availability['foo'] %}
</code></pre>

<p>Beyond that, it's difficult to tell what you are intending with your code. If this doesn't solve your problem, please expand your question with more information and we can give you a better solution.</p>

CC BY-SA 3.0
2014-06-22T16:48:58.390Z
2014-06-22T16:48:58.390Z
Lindsey D
<p>Having already defined foo, I tried this:</p>

<pre><code>{% for block in availability.{{ foo }} %}
</code></pre>

<p>This gives error:</p>

<pre><code>Expected name or number
</code></pre>

<p>Can anyone please tell me the right way to go about this.</p>

CC BY-SA 3.0
2014-06-22T15:45:46.330Z
Can you give a better example of what you are trying to accomplish? What is `foo` and what is `availability`?
Victor
<tags>
Is it possible to call a variable within a tag pair?
# Is it possible to call a variable within a tag pair?

(Asked by: username_0 on 2014-06-22)

Having already defined foo, I tried this:
{% for block in availability.{{ foo }} %}

This gives error:
Expected name or number

Can anyone please tell me the right way to go about this.

**Tags:** tags

> **Comments:**
> **username_1**: Can you give a better example of what you are trying to accomplish? What is `foo` and what is `availability`?  

---

## 3 answers

### Answer by username_0 on 2014-06-22. Score: 1 | Accepted answer

Many thanks for your answers and apologies for the poor example in my question. Before your answers came in I continued researching and found the twig attribute function (http://twig.sensiolabs.org/doc/functions/attribute.html). So I did this:
{% for availability in craft.entries.section('availability2014').limit(52).find( {order: 'availabilityWeekBeginning asc'} ) %}
  {% set foo = attribute (availability, ['availability', craft.request.getSegment(2)|replace('-lake','')|capitalize]|join) %}

  {% for block in foo %}
      //Loop
  {% endfor %}
{% endfor %}

> **Comments:**
> **username_2**: Interesting, thanks for posting your solution!  

---

### Answer by username_3 on 2014-06-22. Score: 5

Try this:
{% for block in availability[foo] %}

The square brackets let you access a variable variable name on an object.
As a general rule you never put {{ }} inside of {% %} tags in twig.


---

### Answer by username_2 on 2014-06-22. Score: 1

Twig isn't like ExpressionEngine, there is no "parse order" to contend with. In Twig, you cannot nest tags within other tags.
So that line of code should look more like this:
{% for block in availability.foo %}

... or even this:
{% for block in availability['foo'] %}

Beyond that, it's difficult to tell what you are intending with your code. If this doesn't solve your problem, please expand your question with more information and we can give you a better solution.


---

