Leveraging `import{}` for Standalone Applications with a Routing System
In a standalone application that doesn't rely on an external framework, using the import feature can be extremely beneficial, especially for managing page-specific meta tags and other components. This approach enhances the flexibility and modularity of each page within your application.
Example of Structuring Routes with `import`:
Consider a routing structure like the following in your standalone PHP application:
$templateEngine->setRoutes([
'*' => [
'/layout.html',
'/components/header.html',
'/components/footer.html',
'/components/forms.html',
],
'' => [
'/pages/index.html',
],
'docs' => [
'/pages/docs.html',
],
'contact' => [
'/pages/contact.html',
],
]);
Dynamic Meta Tag Management:
In each specific page, like docs.html, you can define meta tags or other necessary head elements within a block, say {meta}:
{meta}
{$title = "Dynamic Title for Docs Page"}
{$description = "Description specific to Docs Page"}
{/meta}
By utilizing import in your layout.html, you can dynamically include these meta tags into the head of your HTML structure:
<!DOCTYPE html>
<html lang="{$lang}">
<head>
{import{meta}}
<title>{$title}</title>
<meta name="description" content="{$description}">
<!-- Other head elements -->
</head>
<body>
include{header}
<!-- Page Content -->
include{footer}
</body>
</html>
Advantages:
- Dynamic Content: The use of import allows for dynamic inclusion of content like meta tags, which can be different for each page (like Home, Docs, Contact).
- Modular Structure: This approach facilitates a more modular and maintainable structure for your application, with each component or block being self-contained.
- Simplified Management: Managing meta tags and other head elements becomes straightforward, as they are encapsulated within their respective page templates.
- 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