Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

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

Open
bmcminn opened this issue Jun 18, 2015 · 2 comments
Open

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

bmcminn opened this issue Jun 18, 2015 · 2 comments

Comments

@bmcminn
Copy link

bmcminn commented Jun 18, 2015

// 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'
      ]
    )
  ]);
@bmcminn bmcminn changed the title Passing 'extension' option doesn't override extension value. Need documentation on 'extension' for file loader options Jun 18, 2015
@JustBlackBird
Copy link
Contributor

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
Copy link

jdrydn commented Jan 31, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants