-
Notifications
You must be signed in to change notification settings - Fork 0
Views
(If you are reading this, it's considered that you have read the previous page: https://github.com/FastyPHP/fasty/wiki/Routing)
Fasty currently supports only one template engine - Smarty
It's very fast, reliable, and on top of that, it has a rich syntax
Views (template files) are stored inside public/Templates/Views directory and have a .tpl file extension
To display a view, you can use the helper function view();
By default, Fasty comes with a template called welcome.tpl
To display it, simply add the following code to your web controller class (the one we created in the previous page):
public function index() {
return view('welcome');
}
The view helper function accepts 2 parameters, the first one is mandatory while the second one is optional
view(string $templateName, array $arguments);
The $templateName is obviously the template you want to load
If you want to load a template inside a folder, you can use the traditional folder/template
view('folder/template');
or you could use a . separator Like so:
view('folder.template');
The $arguments param is an array that contains variables that you want to pass to a template you're loading
So for example, you want to pass a variable $hello to the template welcome
You would do so by typing
view('welcome', [
'hello' => 'Hello world!'
]);
And inside the welcome.tpl file, you would access the hello variable by using the following
{$hello}
For a more detailed syntax documentation, please visit the official smarty docs here: http://www.smarty.net/docsv2/en/