CMS Development

ivanoccam
Participant | Platinum Partner
Participant | Platinum Partner

Variable Scopes changed unnoticed

Hi everyone,

 

Last July's Sunday (CET time zone) a customer noticed something went wrong with a page that was working until that day. I've noticed scopes of variables had been changed and are not aligned with preview and debug views.

Check this code:

 

{% set variable = {} %}
{% macro test() %}
  <p>Variable: {{ variable }}</p>
  {% do variable.put("key", "value") %}
  <p>Variable: {{ variable }}</p>
{% endmacro %} 
{{ test() }}

 The result will depend on whether debug or preview mode is actived or not.

This is the result in Debug/Preview:

<p>Variable: {}</p>
<p>Variable: {key: value}</p>

And here is the result in production page:

<p>Variable: </p>
<p>Variable: </p>

 This is resolved defining the variable inside the macro:

{% macro test() %}
  {% set variable = {} %}
  <p>Variable: {{ variable }}</p>
  {% do variable.put("key", "value") %}
  <p>Variable: {{ variable }}</p>
{% endmacro %} 
{{ test() }}

It seems macro tag is isolated from surrounding code.  For loops are not affected.

Anyway, this change broke a page while my leave, causing panic.

 

Additionally, this behavior is reproduced with modules in templates. The broken module was rendered in a Global Partial Template and then the global variable accessed through content.widgets. 
I tried to reach that module to get the data from the custom fields, but it is not defined in content.widgets either. It was ten days ago. 

 

Thanks in advance.

 

0 Upvotes
1 Reply 1
Jaycee_Lewis
Community Manager
Community Manager

Variable Scopes changed unnoticed

Hi, @ivanoccam 👋 Thanks for reaching out. Hey @LMeert @Stephanie-OG @Gonzalo, have you run across anything similar?

 

Thank you! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes