Standalone Mode with Routing System
The PHP Template Engine offers the flexibility to be used in a standalone mode, ideal for creating simple web pages without relying on an external framework. This mode is especially useful for projects where a full-scale framework might be unnecessary or overly complex.
Implementing the Routing System
In standalone mode, instead of setting up input files using `$templateEngine->setFiles([...]);`, the template engine utilizes a basic routing system configured via `$templateEngine->setRoutes([...]);`. This approach allows for defining different templates for different routes or paths within your application.
Configuration:
<?php
$templateEngine = new Nlg\Aurora\Loader([
'views' => '/views',
'cache' => '/cache',
]);
$templateEngine->setRoutes([
'*' => [
'/layout.html',
'/components/header.html',
'/components/footer.html',
'/components/forms.html',
],
'' => [
'/pages/index.html',
],
'docs' => [
'/pages/docs.html',
],
'contact' => [
'/pages/contact.html',
'/components/form.html',
],
]);
$templateEngine->setLanguageConstants([
'hello world' => 'Hello World',
]);
$templateEngine->setVariables([
'lang' => 'en',
'title' => '...',
'description' => '...',
'articles' => [...]
]);
$templateEngine->createCache(true);
print $templateEngine->render("layout");
Key Points:
- '*' specifies templates that are loaded for all routes
- '' represents the homepage
- Custom routes like 'docs' and 'contact' can be defined for specific pages or components.
Using this setup, you can build a complete web page with multiple routes, solely using the NLG template engine, offering a lightweight yet powerful alternative to more complex frameworks.
Ideal for Web Coders and Collaboration with Developers
The template creation method employed by this PHP Template Engine is particularly well-suited for web coders, emphasizing ease of use and accessibility. This approach facilitates an efficient workflow, especially when collaborating with developers in a team environment.
Key Advantages for Web Coders:
- Simplified Template Creation: The template engine allows web coders to focus on designing and structuring web pages without needing deep programming knowledge. This makes it easier to create complex layouts and components.
- Seamless Handoff to Developers: Once the templates are crafted, they can be effortlessly passed on to developers. The structured format of the templates ensures that developers can easily integrate them into the broader application context.
- Enhanced Collaboration: This approach bridges the gap between design and development. Web coders can work on the visual and structural aspects of the web pages, while developers handle the more technical implementation details.
- Maintainability and Scalability: By separating the templates into manageable blocks and components, future updates and enhancements can be executed more efficiently. This separation of concerns not only makes the code more maintainable but also scalable for larger projects.
In summary, the PHP Template Engine is designed to cater to the needs of web coders, providing a user-friendly interface for template creation while ensuring smooth integration with developers' work. This results in a cohesive and efficient team workflow.
- 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