Comments (9)
OW the extension part is all ready solved
from lightncandy.
More information required.... May you provide sample code of this issue? Thanks. And, the input object is subclass of array? does it have the magic method __toString() ?
from lightncandy.
Mmm none of the above, I'm afraid I'll have to add it to all objects if I want to be able to use them.
We are currently using mustache.php but are missing some handlebar helpers and and sometimes the rendering of loops acts strangely.
from lightncandy.
Well, if you mean {{page.title}} should output objectPage->title() , then it is not supported now. It's on road map but may reduce the performance of lightncandy , I may add a flag to support this in this week. (Then , maybe a performance test for this feature)
from lightncandy.
Thank you for the quick replies.
We are already working with many objects so additional support for objects in lightncandy would be great.
Still it surprises me dat typecasting the object to an array before feeding it to the renderer causes these errors. (When I look at the array it seems ok) (array(page=>(array(title=>"test",x=>"b")))
I'll do some simple tests and let you know more.
from lightncandy.
Ok did some tests
$tpl = isset($this->opts['footer']['tpl']) ? $this->opts['footer']['tpl'] : 'include/footer';
$view = isset($this->opts['footer']['view']) ? $this->opts['footer']['view'] : new Footer;
require APP_PATH.'class/lightncandy/src/lightncandy.php';
$template = file_get_contents(DIR_NAME.'themes/'.THEME.'/templates/'.$tpl.'.mustache');
$compiledTemplateDir = APP_PATH.'templates/';
$php_inc = $compiledTemplateDir.$tpl.'.php';
$oLightnCandySettings = Array(
'flags' => LightnCandy::FLAG_STANDALONE || LightnCandy::FLAG_HANDLEBARSJS ,
'basedir' => Array(DIR_NAME.'themes/'.THEME.'/templates'),
'fileext' => Array(
'.mustache',
'.handlebars'
)
);
/* Can the LightNCandy be set once, or should the settings be passed each time?? */
$compiledTemplate = LightnCandy::compile($template, $oLightnCandySettings);
file_put_contents($php_inc, $compiledTemplate);
$renderer = include($php_inc);
if($tpl && $view){
$oArray = (array)$view; // var_dump gives array(1) { ["cookieBanner"]=> bool(false) }
$oFooter = $renderer($oArray);
}
return $oFooter;
The Footer class
<?php
class Footer{
public $cookieBanner;
function __construct(){
$this->cookieBanner = $this->cookieBanner();
}
private function cookieBanner(){
return isset($_COOKIE['accept_cookies']);
}
}
The result is :
Fatal error: Function name must be a string
Update:
The compiled template was empty, the template didn't render (valid Mustache).
I'll use the debug options, to see what is says.
Solved
The template used
{{#links.length}}
<h3>LINKS:</h3>
<ul>
{{#links.list}}
<li>{{val}}</li>
{{/links.list}}
</ul>
{{/links.length}}
Replacing it by this template and simplifying the object, solved the issue:
{{#if links}}
<h3>LINKS:</h3>
<ul>
{{#each links}}
<li>{{val}}</li>
{{/each links}}
</ul>
{{/if}}
from lightncandy.
Ok problem with RAW {{{ var }}} is still here :(
$compiledTemplate = LightnCandy::compile("{{{tt}}}", $oLightnCandySettings);
file_put_contents($php_inc, $compiledTemplate);
$renderer = include($php_inc);
echo $renderer(array('tt'=>"bla bla bla "));
Gives us :
Notice: Array to string conversion in /mnt/htdocs/inbouwWerkmap3.0/application/class/lightncandy/src/lightncandy.php on line 1399
Parse error: syntax error, unexpected '.', expecting '(' in /mnt/htdocs/inbouwWerkmap3.0/application/templates/include/footer.php on line 16
The compiled footer.php:
<?php return function ($in, $debugopt = 1) {
$cx = Array(
'flags' => Array(
'jstrue' => false,
'jsobj' => false,
'spvar' => false,
'debug' => $debugopt,
),
'helpers' => Array(),
'blockhelpers' => Array(),
'scopes' => Array($in),
'sp_vars' => Array(),
'path' => Array(),
);
return ''.Array.'';
}
?>
from lightncandy.
- It is a bug that only happened when FLAG_JSTRUE and FLAG_JSOBJECT and FLAG_RENDER_DEBUG not used. I fixed it.
- There is one problem in your code ......you should fix it.
'flags' => LightnCandy::FLAG_STANDALONE || LightnCandy::FLAG_HANDLEBARSJS ,
should be
'flags' => LightnCandy::FLAG_STANDALONE | LightnCandy::FLAG_HANDLEBARSJS ,
from lightncandy.
awesome!
from lightncandy.
Related Issues (20)
- Valid use for Lightncandy::prepare() HOT 6
- Nested Helpers Unavailable When Rendered
- The problem in PHP8 HOT 7
- Bad indentation in case of nested partials
- Different behaviour than Javascript when modifying context in helper HOT 1
- Hi...broken forum link
- Opencart 1.5.6 Integration
- SafeString fails with FLAG_EXTHELPER | FLAG_BESTPERFORMANCE
- Custom condition helper over payload array with conditions
- Subexpression with a string where zero spaces occur before parenthesis breaks Parser
- Custom Block Helper with blockParams
- PHP Warning: Undefined array key when trying to access unavailable key from parent context
- Possible bug with `$context['flags']['debug']`? HOT 1
- Helpers closure causes error in Laravel HOT 1
- Arrow function helpers generate invalid php code
- Parentheses in subexpression argument cause error
- .git included in vendor distribution causes errors in grunt and other tools HOT 1
- length with @root is causing parse error
- Custom each does not support `as | a index |` syntax
- Multiple `@partial-block`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightncandy.