Template on the go was a feature added to make it easier to create template files easily by taking
advantage of the integrated live server feature. If a rex template file does not exist, we can forward a signal to
the widow's self::load() method to automatically generate the template file when the relative page is visted.
This functionality is achievable through the self::addRex() method. Not only does the template file generate
itself but it also generates on a live state making it possible to continue with development on a live state. The self::addRex()
must however be called before the template is generated to keep it on a live state mode using live server directives.
class Home{
function __construct(){
self::addRex();
self::load('sample', fn() => compile() );
}
}
self::addRex() method will direct the self::load() method to create
the rex file. This means that from the example above, a file sample.rex.php will be
added into the "windows/Rex" directory if it does not already exist.
class Home{
function __construct(){
self::addRex();
self::call($this,
[
window(':') => "index",
window(':users') => "users",
]
)
}
function index() {
self::load('home.index', fn() => compile() );
}
function users() {
self::load('home.users', fn() => compile() );
}
}
self::addRex() method is one which has extensive properties. This means that
the directive to generate a rex file can be inherited by subsequent shutter invoked methods. In the example
above, both the home/index.rex.php and home/users.rex.php files will be generated
once their respective methods are invoked (or relative page visited). This is a top level call that makes it easier to generate rex files.
This functionality can also be restricted only to a specific shutter method through the SELF::ONCALL shutter middleware preload
key.
class Home{
function __construct(){
self::addRex('some.template');
self::load('home.index', fn() => compile() );
}
}
self::addRex() method takes an argument, one which allows it
to extend to a default template file when generating a template file. In this case,
the live status of the template file will be determined by the parent template file
that is inherited from. The example above will generate a template file using the the
default template structure which resembles the format below
template('some.template')
template;