<p>I've solved it by using a different method:</p>
<p>STEP 1
Create a Global Variable (layoutWidth) with a field (layoutWidthIs) and give it the value: normalWidthNow</p>
<p>STEP 2
This is the partial:</p>
<pre><code>
&lt;!-- set layoutWidthCurrently to the global variable layoutWidth --&gt;
{% set layoutWidthCurrently = _globals.get('layoutWidth.layoutWidthIs') %}

&lt;!-- get the value of dropdown field layoutWidth - if normalWidth --&gt;
{% if entry.layoutWidth.value == 'normalWidth' %}

&lt;!-- check that layoutWidthCurrently isn't normalWidth --&gt;
{% if layoutWidthCurrently != 'normalWidthNow' %}
{% do _globals.set('layoutWidth.layoutWidthIs', 'normalWidthNow') %}
&lt;div class=&quot;w3-container&quot;&gt;
&lt;div class=&quot;w3-content&quot; style=&quot;max-width:1240px&quot;&gt;
&lt;div class=&quot;w3-row-padding w3-cell s12&quot;&gt;

&lt;!-- if layoutWidthCurrently is already normalWidth don't do anything --&gt;
{% else %}
{% endif %}

&lt;!-- Do the same, but for fullWidth --&gt;
{% elseif entry.layoutWidth.value == 'fullWidth' %}

&lt;!-- check that layoutWidthCurrently isn't fullWidth --&gt;
{% if layoutWidthCurrently != 'fullWidthNow' %}
{% do _globals.set('layoutWidth.layoutWidthIs', 'fullWidthNow') %}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;!-- if layoutWidthCurrently is already fullWidth don't do anything --&gt;
{% else %}
{% endif %}
{% endif %}```

</code></pre>

CC BY-SA 4.0
2024-11-01T13:10:46.447Z
2024-11-01T13:16:25.283Z
2024-11-01T13:16:25.283Z
Jonathan
<p>Whilst passing a variable to a partial is very useful, I need to be able to set a variable inside the partial that can be read by another partial.</p>
<p>Specifically, I have a partial which sets the layout to be either full width or normal (constrained) width:</p>
<ol>
<li>If full width is chosen, it's just a case of closing divs.</li>
<li>Choosing normal reinstates the closed divs.</li>
</ol>
<p>I want to idiot proof it so the client couldn't set normal when it's already normal. That could get very ugly.</p>
<p>So my strategy is to set a variable that knows whether it is full width or normal width. It's initially set to normal width. The problem comes when changing the status of the variable within the partial. Next time the layout width partial is selected, it thinks it's always normal.</p>

<variable>
Pass Variable back from Partial
# Pass Variable back from Partial

(Asked by: username_0 on 2024-11-01)

Whilst passing a variable to a partial is very useful, I need to be able to set a variable inside the partial that can be read by another partial.

Specifically, I have a partial which sets the layout to be either full width or normal (constrained) width:

1. If full width is chosen, it's just a case of closing divs.
2. Choosing normal reinstates the closed divs.

I want to idiot proof it so the client couldn't set normal when it's already normal. That could get very ugly.

So my strategy is to set a variable that knows whether it is full width or normal width. It's initially set to normal width. The problem comes when changing the status of the variable within the partial. Next time the layout width partial is selected, it thinks it's always normal.

**Tags:** variable


---

## 1 answers

### Answer by username_0 on 2024-11-01. Score: 0

I've solved it by using a different method:
STEP 1
Create a Global Variable (layoutWidth) with a field (layoutWidthIs) and give it the value: normalWidthNow
STEP 2
This is the partial:


{% set layoutWidthCurrently = _globals.get('layoutWidth.layoutWidthIs') %}


{% if entry.layoutWidth.value == 'normalWidth' %}


{% if layoutWidthCurrently != 'normalWidthNow' %}
{% do _globals.set('layoutWidth.layoutWidthIs', 'normalWidthNow') %}





{% else %}
{% endif %}


{% elseif entry.layoutWidth.value == 'fullWidth' %}


{% if layoutWidthCurrently != 'fullWidthNow' %}
{% do _globals.set('layoutWidth.layoutWidthIs', 'fullWidthNow') %}





{% else %}
{% endif %}
{% endif %}```


---

