Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include partial files #312

Open
snoopy4ever opened this issue Jun 17, 2019 · 8 comments
Open

Include partial files #312

snoopy4ever opened this issue Jun 17, 2019 · 8 comments
Labels

Comments

@snoopy4ever
Copy link

Hello there!

I'm not sure if I'm missing something, but I cannot include partials...

So I have my default.hbs file and there I'm trying to include my header:

  {{> header }}

file is located in ./partials/header.hbs and my config for lightncandy is following:

  'flags'		=> LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_SPVARS | LightnCandy::FLAG_INSTANCE | LightnCandy::FLAG_ERROR_EXCEPTION,
  'hbhelpers'	=> $helpers,
  'basedir' => Array(
    '/views',
    '/views/partials'
  ),
  'fileext'	=> array('.hbs')

I've got this error and I'm not sure what I'm doing wrong:

Fatal error:  Uncaught Exception: Can not find partial for 'header', you should provide partials or partialresolver in options in \public_html\vendor\lightncandy\LightnCandy.php:113
Stack trace:
#0 \public_html\vendor\lightncandy\LightnCandy.php(55): LightnCandy\LightnCandy::handleError(Array)
#1 \public_html\Core\lightncandy.php(50): LightnCandy\LightnCandy::compile('{{> header }}\r\n...', Array)
#2 \public_html\loader.php(22): require_once('C:\\VirtualDrive...')
#3 \public_html\index.php(7): require_once('C:\\VirtualDrive...')
#4 {main}
  thrown in \public_html\vendor\lightncandy\LightnCandy.php on line 113

Please help,

Many thanks in advance.

Peter.

@zordius
Copy link
Owner

zordius commented Jun 18, 2019

From your provided information you should using old version of lightncandy or other frameworks based on lightncandy. for older version document you may check here: https://github.com/zordius/lightncandy/tree/v0.23 . And in your stack trace there are something like C:\\VirtualDrive... , maybe you should double confirm your directory settings.

@snoopy4ever
Copy link
Author

Hi @zordius,
Thanks for the info, I'm using latest version downloaded from this repo.
C:\VirtualDrive... path is correct, works with everything else, I had also mustache here previously and includes were working OK, I will try clean installation for now and will test that, will let you know what are the results of that.
Many thanks,
Peter

@snoopy4ever
Copy link
Author

I've done clean deploy on my dev box (CentOS 7, PHP 5.6.40) from here: https://github.com/zordius/lightncandy/tree/master/src

This is my folder structure (maybe I'm missing something):

image

In src I've got copy of Lightncandy, in cache - cache files, in partials I have header.hbs, content of main.hbs is as follows:

{{> header }}

MAIN TEMPLATE {{ test }}

Content of my index.php file is:

<?php

require_once( './src/loader.php' );

use LightnCandy\LightnCandy;

$template = file_get_contents( './main.hbs' );

$config_template = array(
  'flags'     => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_SPVARS | LightnCandy::FLAG_INSTANCE | LightnCandy::FLAG_ERROR_EXCEPTION,
  'basedir'   => Array([
    './',
    './partials'
  ]),
  'fileext'	  => Array([
    '.hbs'
  ])
);

$phpStr = LightnCandy::compile($template, $config_template);

file_put_contents( './cache/cache_' . $cacheName . '.php', '<?php ' . $phpStr . '?>');

$renderer = include( './cache/cache_' . $cacheName . '.php' );

$data = array(
  'test' => 'TEST'
);

echo $renderer( $data );

Same error still persist:

==> /var/log/httpd/ssl_error_log <==
[Tue Jun 18 16:21:24.023740 2019] [:error] [pid 15300] [client 79.173.173.4:62769] PHP Fatal error:  Uncaught exception 'Exception' with message 'Can not find partial for 'header', you should provide partials or partialresolver in options' in /home/www/lnc/src/LightnCandy.php:113\nStack trace:\n#0 /home/www/lnc/src/LightnCandy.php(55): LightnCandy\\LightnCandy::handleError(Array)\n#1 /home/www/lnc/index.php(22): LightnCandy\\LightnCandy::compile('{{> header }}\\r\\n...', Array)\n#2 {main}\n  thrown in /home/www/lnc/src/LightnCandy.php on line 113

When I remove {{> header }} from main.hbs it all works, I would expect that the partials will work same way as in handlebars and mustache?

Many thanks for any help.
Peter.

@zordius
Copy link
Owner

zordius commented Jul 28, 2019

for lightncandy 0.23 partials should be provided by code but not another file, please read document here: https://github.com/zordius/lightncandy/tree/v0.23#partial-support , and do the file loading task yourself.

@flavi1
Copy link

flavi1 commented Sep 11, 2020

Hello.

My problem is the same, but in a more specific context.
I need to parse each individual template before compilation and push the filename in a custom debug stack array during runtime.

I don't want to modify any lightncandy file. (easy updates, bigger code time life).

I will try to extends the LightnCandy main class to override compile and compilePartial methods.

By design, the first parameter of theses methods is directly the template string.
I need it to be a filename, then i will just wrote a new method getTemplateFromFile to resolve the problem.

I hope this won't enter in conflict with any part of lightncandy library, and this can be an helpful idea for anyone.

Thanks

@flavi1
Copy link

flavi1 commented Sep 11, 2020

Oops.
First problem : LightnCandy::compilePartial doesn't seem to be used anywhere. Any suggestion?

@flavi1
Copy link

flavi1 commented Sep 11, 2020

Compiler::partial() method use Partial::compileStatic().
Partial::compileStatic() method use Compiler::compileTemplate().
I will not be able to do what i want without modify anything since it seem to be a closed loop in a lower level than the main LightnCandy class...

Would you like me to post a new feature ticket, or it's ok with this one?

@zordius
Copy link
Owner

zordius commented Sep 12, 2020

Do you mean to use v0.23 ? Or current version?

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

No branches or pull requests

3 participants