Basic Usage of the PHP NLG Template Engine
This section provides a straightforward guide to get started with the PHP Template Engine. Here's how you can set up and render your first template:
Step 1: Loading the Engine
First, ensure that the template engine file is included in your PHP script. You can do this by requiring the engine file at the beginning of your PHP file.
require_once "../src/aurora.php";
Step 2: Creating a New Instance
Next, create a new instance of the template engine.
$templateEngine = new Nlg\Aurora\Loader();
Step 3: Setting Input Templates
Define the template files you want to use. In this example, we are using 'index.html' as our template.
$templateEngine->setFiles([
'index.html'
]);
Step 4: Generating Cache
For initial loading or when changes are made to your templates, enable cache creation. This helps in optimizing the rendering performance.
$templateEngine->createCache(true);
Step 5: Rendering Output
Finally, render the template. The 'layout' specifies the starting block for rendering. In 'index.html', we have defined a 'layout' block containing 'Hello World'.
print $templateEngine->render("layout");
The Template File (index.html)
Here's how the 'index.html' template file looks:
{layout}
<h1>Hello World</h1>
{/layout}
By following these steps, you'll render a simple template that displays "Hello World". This basic setup is just the beginning of what you can achieve with the PHP Template Engine.
- 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