Setting Language Constants
The template engine also supports the definition of language constants, which are crucial for internationalization and localization. These constants are similar to variables but are specifically used for language-related strings.
Defining Language Constants
Language constants are defined using the setLanguageConstants method, where each constant is assigned a corresponding value in an associative array:
$templateEngine->setLanguageConstants([
'hello world' => 'Hello World',
// ... other language constants
]);
This method allows for defining multiple language constants that can be easily managed and updated.
Using Language Constants in Templates
In the templates, language constants are referenced using a specific syntax with backticks ``. This syntax differentiates language constants from regular variables.
Example of referencing a language constant in a template:
{layout}
{`hello world`}
{/layout}
Hello World
Output on Screen
When the above template is rendered, it will output the value associated with the 'hello world' constant. In this case, the output on the screen would be:
Hello World
- 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