Setting Up Input Templates
For the template engine to work effectively, you need to define the input templates that will be used. These templates are essentially the building blocks of your final rendered page.
To ensure effective functioning of the template engine, it is crucial to define the input templates. These templates serve as components and content sections which can be incorporated within your template.
Defining the Templates
Use the setFiles method to define a list of your HTML template files. The order of templates in this list does not affect the processing as each template contains independent blocks that can be utilized as needed.
Here's an example:
$templateEngine->setFiles([
'index.html',
'components/header.html',
'components/footer.html',
'pages/homePage.html',
]);
In this setup, 'index.html' acts as the main template, including the basic structure of the web page, such as the 'layout', while the other files ('header.html', 'footer.html', 'homePage.html') are components that can be included in the main template.
The Main Template File (index.html)
Your main template file (e.g., 'index.html') should include the primary layout structure. This file can incorporate other template components using the include{} syntax.
Here's how the 'index.html' file might look:
{layout}
<!DOCTYPE html>
<html lang="{$lang}">
<head>
<title>{$title}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
include{header}
<section class="container">
<div class="content">
include{content}
</div>
</section>
include{footer}
</body>
</html>
{/layout}
In this example, include{header}, include{content}, and include{footer} are placeholders for other template files. The template engine will replace these placeholders with the respective content from the specified files.
- 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