glowieframework / skeltchgo
Standalone Skeltch templating engine for PHP
Requires
- php: ^7.4|^8.0
- ext-mbstring: *
README
Lightweight PHP templating engine
SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use outside the framework.
Requirements
- PHP version 7.4 or higher
- Composer version 2.0 or higher
Installation
Through Composer:
composer require glowieframework/skeltchgo
Usage
Create a SkeltchGo instance through the static make()
method.
// Include Composer autoloader require_once('vendor/autoload.php'); // Setup SkeltchGo use Glowie\SkeltchGo\SkeltchGo; $skeltch = SkeltchGo::make();
This method returns an instance of ViewRenderer
.
The make()
method accepts three optional arguments:
viewFolder
(string) - Folder where the view files are stored, relative to the running script. (Defaults toviews
)cacheFolder
(string) - View cache folder, relative to the running script. Must have writing permissions. (Defaults tocache
)cache
(bool) - Enable views caching. Highly recommended in a production environment. (Defaults totrue
)
Rendering views
Views must be .phtml
files inside the views folder. Extension is not needed.
From the script
$skeltch->renderView('myView');
From another view
{ view('myView') }
Rendering partials
To render a view in a private scope, use partials. They will not inherit global or parent view parameters.
From the script
$skeltch->renderPartial('myView');
From another view
{ partial('myView') }
Rendering layouts
Layouts must be .phtml
files inside the views folder. Extension is not needed. The second parameter is an optional view file to render within the layout.
From the script
$skeltch->renderLayout('myLayout', 'myView');
From another view
{ layout('myLayout', 'myView') }
To retrieve the internal view content inside the layout use:
{ content }
Passing parameters
There are two ways of passing parameters to the views:
// Globally to all views at once $skeltch->view->myParam = 'Lorem ipsum'; // Restricted to a single view and its childs $skeltch->renderView('myView', [ 'myParam' => 'Lorem ipsum' ]);
Then retrieve it in the view as a property of itself:
{{ $this->myParam }}
View helpers
Setup a helper method by passing a name and a closure to the helper()
method:
$skeltch->helper('sayHello', function($name){ return "Hello, $name!"; });
Then call it in your view file using:
{{ $this->sayHello('World') }}
Documentation
To learn how to use all methods and templating syntax, read Skeltch complete documentation.
Note: some Skeltch methods are restricted to the framework environment and are not available in SkeltchGo.
Credits
SkeltchGo and Glowie are currently being developed by Gabriel Silva.