Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Parser package - share views between Javascript and PHP
  • Hi everyone,

    have a project developped with fuelphp 1.7 in which am using basic PHP views for my pages in general (i.e.: fuel/app/views/dashboard.php).
    nd HTML handlebars views for the content details for each of these pages
    (i.e.: public/assets/templates/panelstats.html).

    My goal is to share public HTML templates with PHP with the help of the fuel Mustache parser for example.

    My problem is that I can’t give « public » template views to the « forge »
    method => View::forge('path/to/view’), in the doc I can read: « View files
    should be relative to the app/views directory and be supplied without the .php file extension. ».

    I have 2 questions:
    - How could I achieve the possibility to share templates between PHP and
    JavaScript in my application? (with mustache for example)

    - The most would be with the fuelphp Handlebar parser, but it’s not available in fuelphp 1.7, however is it possible to get it?

    Thank you very much for your help


  • Harro VertonHarro Verton
    Accepted Answer
    There isn't currently a Handlebars parser for Fuel, and I don't know of any third-party parser for it.

    There is a PHP implementation for Handlebars ( so it shouldn't be too difficult to make a parser class for it.

    If it is developed by us, it will be going to 1.9/dev, there is no feature support for older versions anymore. Upgrading from 1.7 to 1.8.x (or 1.9/dev, which is production-stable as well) shouldn't be too difficult, and you'll get PHP 7.x compatibility with it, which you will need soon.
  • Thanks for the fast answer,
    I will upgrade to fuelphp 1.9 very soon. so I will have the Handlebars parser available :-)

    My last encountered difficulty is that I need to give Public template files to render views.
    Example: View::forge('public/assets/templates/myview.html’), but it's not working :-/
    Impossible to forge Public view paths in fuelphp??
    (I need to keep these views Public so that I can have easy access with javascript on client side)

    Many thanks!
  • Harro VertonHarro Verton
    Accepted Answer
    No. I wrote "if it has to be developed by us, we will add it to 1.9/dev". ;-) I can add it to the todo list, but no guarantee as to when it will be available.

    The design philosophy of Fuel is that you keep as much as possible outside the docroot. 

    Every view parser is designed to work with the structure the parser itself requires, which is one of the reasons a special Handlebars parser class needs to be created, so it can access these files (parser classes extend the View class so parser specific functionality becomes available).

    As a workaround, you can manually add a search path before forging the View, and delete that path after, see You can use the list_files() method to check if after you've added the search path, the Finder can locate your html templates.

    This should also work in 1.7.
  • Ok, understood.
    Yes would be great if you could add "Handlebars" to the todo list :-) :-) !!
    Thank you again for your help and long life to FuelPHP ;-) !
  • Ok, will do. And thanks. ;-)

Howdy, Stranger!

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

In this Discussion