Slim Views Vs Normal Views

Iam just wondering.
If The supported slim views (TWIG and SMARTY) have anY advantages over normal PHP views which Many of us are used to…

What extra advantages does one get from using slim views as opposed to normal views we are used to???:

The supported views are Twig & PHP…

If you’re confident that you won’t introduce XSS vulnerabilities then PHP view is fine.

The actual advantage depend on your requirements. There is a small learning curve, but worth the pay.

  • Helps seperating developer and designers tasks
  • Insulating the templates from PHP, creates a controlled separation of presentation from business logic
  • Sandboxing. ( You can have user (third party / non trustable ) uploaded templates safely )
  • Portability : twig has JS implementation too twig.js twig.js
  • Include templates facility ( like PHP require / include )
  • Template Inheritance ( it helps you assembling pages in flexible way)
  • Built in Cache facility
  • Different Loaders ( Create your own Loader that may load the template from DB or remote Servers base on custom conditions )
  • Easily change look and feel of your web app ( say theme based UI )
  • When you are developing the app as a team, especially when restricting full code access to all.

Slim Doc >> http://www.slimframework.com/docs/features/templates.html#the-slimtwig-view-component

You are not limited to the Twig-View and PHP-View components. You can use any PHP template system provided that you ultimately write the rendered template output to the PSR 7 Response object’s body.


I recommend use Twig directly (instead of using slimphp/Twig-View). You can have full access to all advanced features that twig provide. For example get full access to Different Loaders

To fully understand the advantages, spend some time practically on Twig.

TWIG

SMARTY

1 Like

thanks for detailed answers @Susanth.Com @akrabat

1 Like

100% agreed with everything @Susanth.Com said. You really want to use a template engine these days …

1 Like