Git Product home page Git Product logo

Comments (9)

reno1979 avatar reno1979 commented on August 25, 2024

OW the extension part is all ready solved

from lightncandy.

zordius avatar zordius commented on August 25, 2024

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.

reno1979 avatar reno1979 commented on August 25, 2024

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.

zordius avatar zordius commented on August 25, 2024

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.

reno1979 avatar reno1979 commented on August 25, 2024

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.

reno1979 avatar reno1979 commented on August 25, 2024

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.

reno1979 avatar reno1979 commented on August 25, 2024

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.

zordius avatar zordius commented on August 25, 2024
  1. It is a bug that only happened when FLAG_JSTRUE and FLAG_JSOBJECT and FLAG_RENDER_DEBUG not used. I fixed it.
  2. 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.

reno1979 avatar reno1979 commented on August 25, 2024

awesome!

from lightncandy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.