Rock icon indicating copy to clipboard operation
Rock copied to clipboard

Variable scope changes inside workflowactivate tag using Fluid

Open leahjennings opened this issue 2 years ago • 0 comments

Prerequisites

  • [X] Put an X between the brackets on this line if you have done all of the following:
    • Did you perform a search at https://github.com/issues?q=is%3Aissue+user%3ASparkDevNetwork+-repo%3ARock to see if your bug or enhancement is already reported?
    • Can you reproduce the problem on a fresh install or the demo site?
    • Did you include your Rock version number and client culture setting?

A Picture Is worth a Thousand Words

Using Fluid: image

Using DotLiquid: image

Description

While using the Fluid Lava engine, a variable assigned at the "parent" level and then used inside the {% workflowactivate %} block seems to establish the variable inside the {% workflowactivate %} block as a differently scoped variable. For example, I've used the {% workflowactivate %} command inside of a {% for %} loop to count records processed. However, the following example code doesn't increment the counter variable because Fluid treats the scope differently.

{% assign list = "1,2,3,4,5,6,7,8,9,10" | Split: "," %}
{% assign counter = 1 %}

{% for i in list %}
    Loop iteration #{{ forloop.index }}
    
    {% workflowactivate workflowtype:'288' %}
        {% assign counter = counter | Plus:1 %}   
        <br>- Counter inside workflowactivate: {{ counter }}
    {% endworkflowactivate %}
    <br>- Counter outside workflowactivate: {{ counter }} <br><br>
{% endfor %}

I don't know if this is just the nature of Fluid or an actual bug, however I've seen it twice now cause issues (once in plugin code and once in my own). If it is just the nature of the engine, it would be great for that to be documented more clearly here.

Steps to Reproduce

  1. Go to the demo site and add an HTML Content Block to a page
  2. Make sure the site is running on the DotLiquid lava engine
  3. Add the above code from the Description section and save (be sure to set the block to allow workflowactivate commands)
  4. Notice how the output increments the counter variable outside of the workflowactivate command (as I would expect)
  5. Now, change the lava engine to Fluid from the Global Attributes setting
  6. Go back to the page where you added the code
  7. Notice how the counter variable outside of the workflowactivate command never increments

Expected behavior:

If a variable is established outside of the workflowactivate command and is subsequently incremented inside that command, I would expect that the variable when used outside of that command shows the incremented value.

Actual behavior:

The variable's value inside of the workflowactivate command is scoped only to that command and is not usable outside of that command.

Versions

  • Rock Version: [Rock McKinley 13.6 (1.13.6.1)]
  • Client Culture Setting: [en-US]

leahjennings avatar Aug 09 '22 15:08 leahjennings