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.
- Installation - Installing Aurora Template
- Usage - Basic Usage of the PHP NLG Template Engine
- Storage-Setting Directories for Templates and Cache
- Templates - Setting Up Input Templates
- Variables - Setting Variables in the System
- Language Constants- Setting Language Constants
- Cache - Managing Cache Creation
- Router - Standalone Mode with Routing System
- Using the PHP Template Engine
- Blocks - Block Based template engine
- Using variables - How to use variables in templates
- Calculations - Isolation and Sharing Variables
- Include and Import - include vs. import in the Template Engine
- Import - Leveraging `import{}` for Standalone Applications with a Routing System
- Resources - Adding Resources to Templates
- Control Structures - `if`, `else if`, `else`
- Ternary Operator - How to approach to ternary operator
- Macros - Macros in Template Engines - Understanding the Concept
- Custom Macros - Creating Custom Macros in Template Engines
- Forms - Creating Forms in the Template Engine
- Custom forms - Customizing Forms in the Template Engine
- Custom PHP Forms - PHP Developer's Guide to Customizing Form Templates in the Template Engine
- Curly Brackets - Handling Curly Brackets in Text Content
- Error Handling - Error Handling in PHP Template Engine
- Tests