Setting Directories for Templates and Cache
When creating a new instance of the template engine, you can specify the directories for your templates and cache. This is particularly useful if you have a custom project structure.
Here's how you can set custom directories:
$templateEngine = new Nlg\Aurora\Loader([
'views' => '/views',
'cache' => '/cache',
]);
In this example, the engine will look for template files (*.html) in the '/templates' directory and store the cache files in the '/cacheStorage' directory.
Default Settings
If you don't specify these directories, the engine will use the default settings:
- Templates: Looked up in the 'views' directory.
- Cache: Stored in the 'cache' directory.
These default settings work well for most basic projects, but you might want to customize them as your project grows.
Full snippet:
<?php
require_once "../src/aurora.php";
$templateEngine = new Nlg\Aurora\Loader([
'views' => '/views',
'cache' => '/cache',
]);
$templateEngine->setFiles([
'index.html'
]);
$templateEngine->createCache(true);
print $templateEngine->render("layout");
- 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