SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use outside the framework.
- PHP version 7.4 or higher
- Composer version 2.0 or higher
Through Composer:
composer require glowieframework/skeltchgo
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
)
Views must be .phtml
files inside the views folder. Extension is not needed.
From the script
$skeltch->renderView('myView');
From another view
{ view('myView') }
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') }
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 }
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 }}
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') }}
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.
SkeltchGo and Glowie are currently being developed by Gabriel Silva.