<p>Surrounding text in quotes declares it as a string, whereas no quotes will assume variables. If you remove the quotes, you should get what you need.</p>

<pre><code>{% set foo = entry.title %}
{{ foo }}
</code></pre>

<p>EDIT:</p>

<blockquote>
  <p>I realy want to render a string and get the fieldvalue. A other example would be like this: I have a Variable with a Prefix and now i would like to output a field with this prefix: {% set foo = "entry."~ prefixVar ~ "_fieldName" %} {{ foo }}. Is that possible?</p>
</blockquote>

<p>I am not sure if that's possible when accessing keys through the dot formatting (ie. <code>array.keyname</code>)</p>

<p>But you could tweak the approach a little bit, to access dynamic keys in <code>entry</code> using the <code>attribute()</code> twig function, such as:</p>

<pre><code>{% set foo = attribute(entry, prefixVar~"_fieldName") %}
</code></pre>

CC BY-SA 3.0
2015-12-02T05:05:13.487Z
I realy want to render a string and get the fieldvalue. A other example would be like this: I have a Variable with a Prefix and now i would like to output a field with this prefix: {% set foo = "entry."~ prefixVar ~ "_fieldName" %} {{ foo }}. Is that possible?
Tom Bauer
CC BY-SA 3.0
2015-12-02T05:20:08.197Z
Edited my answer, hopefully that should accomplish what you need!
taylor
CC BY-SA 3.0
2015-12-02T04:43:23.647Z
2015-12-02T05:19:43.663Z
2015-12-02T05:19:43.663Z
taylor
<p>I would like to output a field from a variable like this:</p>

<pre><code>{% set foo = "entry.title" %}
{{ foo }}
</code></pre>

<p>In this example it outputs "entry.title".</p>

<p>Other Example like this:</p>

<pre><code>{% set prefixVar = "en_" %}
{% set foo = "entry."~ prefixVar ~"title" %}
{{ foo }}
</code></pre>

<p>In this example it outputs "entry.en_title". Is it possible in Twig to get the content of the entry field instead of the string?</p>

<templating>
Parse a String dynamic in Twig
# Parse a String dynamic in Twig

(Asked by: username_0 on 2015-12-02)

I would like to output a field from a variable like this:
{% set foo = "entry.title" %}
{{ foo }}

In this example it outputs "entry.title".
Other Example like this:
{% set prefixVar = "en_" %}
{% set foo = "entry."~ prefixVar ~"title" %}
{{ foo }}

In this example it outputs "entry.en_title". Is it possible in Twig to get the content of the entry field instead of the string?

**Tags:** templating


---

## 1 answers

### Answer by username_1 on 2015-12-02. Score: 2 | Accepted answer

Surrounding text in quotes declares it as a string, whereas no quotes will assume variables. If you remove the quotes, you should get what you need.
{% set foo = entry.title %}
{{ foo }}

EDIT:

I realy want to render a string and get the fieldvalue. A other example would be like this: I have a Variable with a Prefix and now i would like to output a field with this prefix: {% set foo = "entry."~ prefixVar ~ "_fieldName" %} {{ foo }}. Is that possible?

I am not sure if that's possible when accessing keys through the dot formatting (ie. array.keyname)
But you could tweak the approach a little bit, to access dynamic keys in entry using the attribute() twig function, such as:
{% set foo = attribute(entry, prefixVar~"_fieldName") %}

> **Comments:**
> **username_0**: I realy want to render a string and get the fieldvalue. A other example would be like this: I have a Variable with a Prefix and now i would like to output a field with this prefix: {% set foo = "entry."~ prefixVar ~ "_fieldName" %} {{ foo }}. Is that possible?  
> **username_1**: Edited my answer, hopefully that should accomplish what you need!  

---

