compile(),
view(), rex() and raw() functions. These functions are used
to render rex template files through the compiler class.
compile() function is the root function for rendering template files.
Prior to version 2.0, it was not a stand alone function but after recent improvements, it is
now capable of rendering template files alone using the Compiler engine. There are three ways by which
this function can be used in window files to render template files. The sample of the usuage are shown
below
The boy is {{ $age }} years today
home template file through the compiler function as shown below:
<?php
namespace spoova/mi/windows/Routes/Home;
use window;
class Home extends Window {
function __construct() {
// The boy is 15 years today
self::load('home', fn() => compile(['age' => '15']));
}
}
self::load() which is a window method tells the compiler to render the template file immediately
as a page without using any print or echo word before it. In previous versions,
this is the known way to render template files. While this approach will also work in recent versions, starting from version 2.0,
we can now use the compiler as a stand alone function without depending on the
the self::load() method as below:
<?php
namespace spoova/mi/windows/Routes/Home;
use window;
class Home extends Window {
function __construct() {
// The boy is 15 years today
echo compile('home', ['age' => '15']);
}
}
<?php
namespace spoova/mi/windows/Routes/Home;
use window;
class Home extends Window {
function __construct() {
$markup = compile('home', ['age' => '15'])->rex();
vdump($markup); // view rendered markup
}
}
compile() function returns a Compiler object, there are couple of
extended functions we can perform on the compile() function. Visit
version 2.0 compiler class release notes to learn more
about compiler object.