<p>You've assigned the string <code>'work modifierClass'</code> to the <code>bodyClass</code> variable, rather than adding the <em>value</em> of the <code>modifierClass</code> variable to <code>bodyClass</code>. </p>

<p>You can assign the value of <code>modifierClass</code> to <code>bodyClass</code> like this:</p>

<pre><code>{% set bodyClass = 'work ' ~ modifierClass %}
</code></pre>

<p>The ~ (tilde) character is Twig's string concatenation operator. </p>

<p>You could even remove the <code>modifierClass</code> variable altogether and just do this:</p>

<pre><code>{% set bodyClass = 'work ' ~ entry.shortName %}
</code></pre>

CC BY-SA 4.0
2018-12-01T20:49:09.620Z
Thanks for the solution. I am newish to Craft and was unaware of the concatenation operator in Twig. I have dumped the variable and placed the entry field in the `bodyClass` variable.
Mike Hermary
CC BY-SA 4.0
2018-12-01T20:10:28.503Z
2018-12-01T20:10:28.503Z
Martin Spain
<p>I have created a plain text field that is assigned to a section and is available in the tabs for entries in that section. I want to use this field's value to modify the CSS on my template. My _entry.html file looks like the following:</p>

<pre><code>{% extends "_layouts/site" %}
{% set title = entry.title %}
{% set modifierClass = entry.shortName %}
{% set bodyClass = "work modifierClass" %}

{% block main %}
&lt;section class="entry is-centered cf"&gt;
  &lt;article&gt;
  &lt;/article&gt;
&lt;/section&gt;
{% endblock %}
</code></pre>

<p>I have assigned the entry.shortName to the customClass variable, but it is not working correctly. The text "modifierClass" is outputted in the body tag instead of what is entered in the entry.shortName field. If I place the <code>{{ entry.shortName }}</code> within the <code>&lt;article&gt;</code> tags, it is outputted correctly there.</p>

<p>Any reason why this is not working? Or am I not understanding how field values can be assigned to variables.</p>

<p>Cheers,</p>

<entries><entries-field>
Use an entry field's value in body class
# Use an entry field's value in body class

(Asked by: username_0 on 2018-12-01)

I have created a plain text field that is assigned to a section and is available in the tabs for entries in that section. I want to use this field's value to modify the CSS on my template. My _entry.html file looks like the following:
{% extends "_layouts/site" %}
{% set title = entry.title %}
{% set modifierClass = entry.shortName %}
{% set bodyClass = "work modifierClass" %}

{% block main %}

  
  

{% endblock %}

I have assigned the entry.shortName to the customClass variable, but it is not working correctly. The text "modifierClass" is outputted in the body tag instead of what is entered in the entry.shortName field. If I place the {{ entry.shortName }} within the  tags, it is outputted correctly there.
Any reason why this is not working? Or am I not understanding how field values can be assigned to variables.
Cheers,

**Tags:** entries, entries-field

---

## 1 answers

### Answer by username_1 on 2018-12-01. Score: 3 | Accepted answer

You've assigned the string 'work modifierClass' to the bodyClass variable, rather than adding the value of the modifierClass variable to bodyClass. 
You can assign the value of modifierClass to bodyClass like this:
{% set bodyClass = 'work ' ~ modifierClass %}

The ~ (tilde) character is Twig's string concatenation operator. 
You could even remove the modifierClass variable altogether and just do this:
{% set bodyClass = 'work ' ~ entry.shortName %}

> **Comments:**
> **username_0**: Thanks for the solution. I am newish to Craft and was unaware of the concatenation operator in Twig. I have dumped the variable and placed the entry field in the `bodyClass` variable.  

---

