Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Location for adding Auth valiation with TWIG template
  • I am trying to add this code chunk in the main template of the site. It's a TWIG template which will provide a constant look across all the pages.

    As I am not able to add this check() function of Auth class, how best can I implement in my .twig file?

    If I should make the Auth::instance()->check() as a twig varibla and use it, where would I assign that?

    Sorry, if my questions looks silly. I am starting new with FuelPHP and TWIG.

    http://bin.fuelphp.com/snippet/view/wg
  • HarroHarro
    Accepted Answer
    I've never used Twig, but I think the idea is to keep code out of your templates.

    Twig allows you to add additional functionality using extensions. You can have a look at classes/twig/fuel/extension.php in the Parser package, to see what is all possible.

    You can create your own extension class. If you create a parser.php config file in your app/config folder, you can define this class as a Twig extension, and the parser will load it automatically. Check the config in the Parser package to see what the structure of the config file is, the included extension class is loaded in exactly the same way.

    Having said that, it might not be a bad idea to add Auth::check to the default extensions. I'll put that on the todo list.
  • Thanks for the response.

    I will see on the extension class and understand how to proceed.

    Thanks in advance for adding the check() in the default extensions list.
  • Also consider this

    Auth::instance()->get_screen_name()

    Adding such functions to default list will be really useful.
  • The problem with this is: where to stop. Everyone finds something useful. We can't just put the entire framework in the extension.

    Personally I already think there is too much in there. There should be no processing in a template, it should be done in the Controller (or better, a Viewmodel), and passed on to the View as data.
  • Cool. Got your point.. Thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion