The compiler function now uses strings as rex file paths starting from version 2.0 upwards
namespace spoova/mi/windows/Routes;
use Window;
use spoova/mi/core/classes/Ajax;
class Home extends Window {
function __construct() {
$Ajax = new Ajax;
$myArray = [1,2,3];
self::load('home', fn() => compile('user.home') );
}
}
self::load() method will assume that the file name "home" (i.e windows/Rex/home.rex.php) supplied is the intended rex template file.
file.
The former behaviour of compile function with array arguments still remains the same
namespace windows/Routes;
class Home {
function __construct() {
self::load('sample_file', fn() => compile(['name'=>'foo']));
}
}
Previously, the compiler function does not exist as a stand-alone function. It needs to be used within the Res::load()
or a window's "self::load()" method. The new updates now ensures that the compile() function can exist as a stand alone.
namespace spoova/mi/windows/Routes;
use Window;
class Home extends Window{
function __construct() {
echo compile('sample', ['name'=> 'foo']);
}
}
Since the compile function returns a Compiler object, it is only natural that we discuss the Compiler class itself. Compiler class introduced in spoova 2.0 version, is the template engine class that helps to render the rex template files in a structured form providing some form of flexibility in the way template files are managed and rendered. The following code lines reveals how to render a rex template from the compiler class:
namespace spoova/mi/windows/Routes;
use Window;
use spoova/mi/core/classes/Compiler;
class Home extends Window {
function __construct() {
$args = ['name' => 'foo'];
$Compiler = new Compiler('sample', $args);
$Compiler->compile(); //compile and print page
}
}
compile() method will compile the entire file and render the
content on the webpage. There are also other activities we can perform with this class. For more details about the compiler class, visit
here.
@()@ is used, it is usually
resolved as a single "at" sign @. So a template directive @(domurl())@ will be resolved as
@domurl(). The scope of this comment has been expanded which calls for remodification as it is not only used for directives anymore. Contrary to the
previous behaviour the new behaviour will return its direct content. This means that an additional "at" sign will no longer be added by default. Hence,
@(domurl())@ for example, will now return domurl() while
@(@domurl())@ will now return @domurl(). The following samples reflect the new behaviour:
| Comment (sample) | Response |
|---|---|
@(domurl())@ | domurl() |
@(@domurl())@ | @domurl() |
@({{}})@ | {{}} |