Fat-Free Framework – 8. Using the templating engine of the framework

Created at: October 21, 2016; Last update: October 21, 2016

Even though it’s a tiny framework, Fat-Free has a templating engine that we can use. In order to do this, instead of calling the View class, we call the Template class:

But what can we do with this template engine? Well… Besides the fact that it’s faster to work with it, it is also safer (or at least “they say” it is).

Let’s now see how or HomepageView.php looks like:

And how we can make it look lighter by using the templating engine:

Wow… Much shorter…

What is nice about the templating engine is the fact that it can use hive‘s variables directly and not by passing the values to an intermediary variable. If we return to our Homepage.php controller we can do something as follows:

But what if we have arrays?

More on the templating engine can be found here: https://fatfreeframework.com/views-and-templates#PHPasaTemplateEngine

Let us also talk about importing views, or “partials”. Inside your templates you can import other templates by using an “include” tag:

You can also use dinamically created views that you’ve created and set in the controller:

..and yet… there are many things that the template can do. Do give a visit to the Fat-Free Framework’s documentation: https://fatfreeframework.com/views-and-templates#PHPasaTemplateEngine

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.