volta-framework / component-template
A HTML - PHP template module based on the PHP build in template engine.
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/volta-framework/component-template
Requires
- php: >=8.1
README
An HTML - PHP template module based on the PHP build in template engine.
%%{init: {'theme':'dark'}}%%
classDiagram
class Volta_Component_Templates_Exception
Exception<|--Volta_Component_Templates_Exception
class Exception
class Stringable {
<<interface>>
}
class Throwable {
<<interface>>
}
StringAble..|>Throwable
Throwable..|>Exception
class Volta_Component_Templates_NotFoundException
Volta_Component_Templates_Exception<|--Volta_Component_Templates_NotFoundException
class Volta_Component_Templates_Template {
}
class Volta_Component_Templates_TemplateInterface {
<<interface>>
}
Volta_Component_Templates_TemplateInterface..|>Volta_Component_Templates_Template
class ArrayAccess {
<<interface>>
}
ArrayAccess..|>Volta_Component_Templates_Template
Stringable..|>Volta_Component_Templates_Template
class Volta_Component_Templates_View {
}
Volta_Component_Templates_Template<|--Volta_Component_Templates_View
Loading
Usage
use Volta\Component\Templates\Template as View // Set the Base Directory globally // Note: In Volta all directory references ends with a slash View::setBaseDir('/path/to/templates/directory/'); // Create a view with basic placeholders $view = new View('layout.html.php', [ 'title' => 'Unknown page' ]); // add placeholders using the set function $view->set('description', 'A simple home page') // or use array access $view['keywords'] = 'home, simple'; // add the template for the content and overwrite some off the parents // placeholders $view->addSubTemplate('content', 'content.html.php', ['title' => 'Contact']) // render the view echo $view;
layout.html.php
<?php ?> <!DOCTYPE html> <html> <head> <title><?= $this->get('title', 'No Title'); ?></title> <link rel="stylesheet" href="/assets/css/main.css"> </head> <body> <h1><?= $this['title']; ?></h1> <?= $this->getSubTemplate('content'); ?> </body> </html>
content.html.php
<?php ?> <h2><?= $this['title']; ?></h2>