Setting Variables in the System
To enable dynamic content within templates, the template engine allows you to set variables that can be utilized across all templates. These variables are set using the setVariables method.
Defining Variables
Here's how you can define variables for use within your templates:
$templateEngine->setVariables([
'lang' => 'en',
'title' => 'NLG template engine',
// ... other variables
]);
In the code you've already established, these variables will be accessible and can be integrated throughout the template engine.
Displaying Variable Values
To display the value of a variable within your templates, use the following syntax:
{layout}
<!DOCTYPE html>
<html lang="{$lang}">
<head>
<title>{$title}</title>
<meta name="description" content="">
<meta charset="UTF-8">
...
{/layout}
This approach renders the respective values of `lang` and `title` variables wherever they are referenced in the template.
Defining New Variables within Templates
Besides pre-defining variables in PHP, it's also possible to define new variables directly within the template files. This feature adds an extra layer of flexibility, allowing for on-the-fly modifications and dynamic content generation based on different conditions or contexts
- 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