XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

Need documentation on 'extension' for file loader options #125

Open bmcminn opened 9 years ago

bmcminn commented 9 years ago
// My Setup
OS: Win7 Pro 64bit
PHP Version: 5.6.6
Running CLI PHP server instance for local dev

I traced this issue back to the Handlebars\Loader\FilesystemLoader.php file and noticed in the getFileName() method, echoing $this->_extension shows the value is still the default ".handlebars" string instead of the shorthand I defined in my $options argument on my Handlebars instance.

<?php
  // My config:
  // ... I have a number of other config values including constant defines for VIEWS_DIR

  use Handlebars\Handlebars;

  $hbs = new Handlebars([
    'loader'          => new \Handlebars\Loader\FilesystemLoader(VIEWS_DIR)
  , 'extension'       => '.hbs'
  , 'partials_loader' => new \Handlebars\Loader\FilesystemLoader(
      VIEWS_DIR
    , [
        'prefix' => '_'
      ]
    )
  ]);

  $hbs->render($template, ['title' => 'testing']);

https://github.com/XaminProject/handlebars.php/blob/master/src/Handlebars/Loader/FilesystemLoader.php#L190-L195


The end result is that Handlebars errors out saying it can't find my template because it isn't using the right file extension.


EDIT: Realized the config I setup wasn't being passed to the FilesystemLoader instance :p

I'm wanting to add a write up on the Fileloader config properties, so I'll see about getting a pull request going this weekend.

  // initialize handleabrs
  use Handlebars\Handlebars;

  $hbs = new Handlebars([
    'loader' => new \Handlebars\Loader\FilesystemLoader(
      VIEWS_DIR
    , [
        'extension'       => VIEWS_EXTENSION
      ]
    )

  , 'partials_loader' => new \Handlebars\Loader\FilesystemLoader(
      VIEWS_DIR
    , [
        'prefix'    => '_'
      , 'extension' => '.hbs'
      ]
    )
  ]);
JustBlackBird commented 9 years ago

You cannot specify extension option at Handlebars instance and it's a correct behavior. There are several loaders and only FilesystemLoader one operates with files and needs an extension to load them. That's why extension option is only specified in FilesystemLoader constructor.

So I don't see any problems here.

jdrydn commented 8 years ago

I love the [] over array() in these examples! :wink: