Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Handlebars: How to handle partial views?
  • Hello,   
    I have a question about how to call partial files using the Handlebars parser.

    In my example I have this 2 templates (which are in different folders):
    "views/auth/mainview.html" and "views/auth/myfolder/mypartial.html"

    With Mustache I managed to make it work by doing this way:
       
    \Parser\View_Mustache::parser()
        ->setPartialsLoader(
        new Mustache_Loader_FilesystemLoader(
            APPPATH.'views',
            array('extension' => '.html')
        )
    );

    Then I forge my view by doing this
    View::forge('auth/mainview.mustache', $data, false);

    in "mainview.html" I display my partial file by doing this:
    {{> auth/myfolder/mypartial}}


    With Handlebars, I've got some difficulties.
    I did like this:
    View::forge('auth/mainview.handlebars', $data, false);

    in "mainview.html" I display my partial file by doing this:
    {{> auth/myfolder/mypartial}}

    => The "bug" I have is that the called partial return the path of the partial:
    "/Users/gwen/Documents/www/myproject/fuel/app/views/auth/myfolder/mypartial.html"
    Instead of its content!

    My question is, how to handle partials with Handlebars within fuelphp?

    Thank you for your help
    Gwen
  • For Mustache you need to configure the "partials_loader" option in the config with the path(s) you want to pass, you don't need to modify code or set your own partial loader.

    For Handlebars I've pushed an fix to return the file contents instead of the file name. I misinterpreted the functionality of the partial loader.
  • Thank you,
    the content is now displayed :-)

    However I have got a new error:
    The content of the partial is displayed "before" the main view and the params given are not interpreted in the partial view.

    mainview.html:
    <h1>My main view</h1>
    {{> auth/myfolder/partialbasic}}

    partialbasic.html:
    <h1>blabla, myvar={{myvar}}</h1>

    What I have displayed on my screen is something like that:

    blabla, myvar={{myvar}}


    My main view

  • Ok. So it's included but not rendered? I'll have a look again.
  • Yes I think so,
    thanks
  • Harro VertonHarro Verton
    Accepted Answer
    Pushed a new update using this code: https://zordius.github.io/HandlebarsCookbook/9902-lcop-partialresolver.html#FileResolver so that should be ok?
  • Ça marche!!
    It's working, Thank you :-)

    In parallel I did some tests with the 'helpers' config in parser.php,
    it's working good

    I keep digging ;-)
  • Harro VertonHarro Verton
    Accepted Answer
    Pas de quoi. ;-)

Howdy, Stranger!

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

In this Discussion