NetLife Guru

Calculations

Aurora supports block-based calculations, where the scope of variable modifications is confined to the block in which they occur, unless specifically imported into another block. Let’s break down the scenarios you’ve mentioned.

Isolated Calculations within Blocks

In this example, calculations within the {calculate} block do not affect the {layout} block. Each block operates independently, maintaining its own scope for variables:


    {calculate}
      {$a += 1}
      {$a} // Output is 2
    {/calculate}

    {layout}
      {$a = 1}
      include{calculate}
      {$a} // Output is 1, unchanged by the {calculate} block
    {/layout}

In this case, despite incrementing $a in {calculate}, its value in {layout} remains unaffected due to the isolated scope of each block.

Sharing Calculated Values Across Blocks

To influence the value of $a in {layout} based on the calculations in {calculate}, you use import instead of include. This approach effectively extends the scope of {calculate} to {layout}, allowing changes in {calculate} to reflect in {layout}:


    {calculate}
      {$a += 1}
      {$a} // Output is 2
    {/calculate}

    {layout}
      {$a = 1}
      import{calculate}
      {$a} // Output is now 2, affected by the {calculate} block
    {/layout}

In this example, import{calculate} means that the changes made to $a in the {calculate} block are carried over to the {layout} block, overriding its original value.

This flexible system allows you to control the scope and impact of calculations and variable manipulations across different blocks within your template engine. This approach is particularly useful for managing dependencies and interactions between various sections of your templates, ensuring that changes are made only where intended.