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

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

0 thoughts on “Fat-Free Framework – 8. Using the templating engine of the framework

  • Do you have any example? how to implement the relationship between two or more tables with Cortex in simple steps. I really don’t understand the tutorials were explained on their github page.


  • Great tutorial. Very simple and easy to understand. It’s much better than the actual documentation, really. When is the next parts going to be posted ?

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

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