bobthecow / mustache.php

A Mustache implementation in PHP.
http://mustache.github.io/
MIT License
3.24k stars 420 forks source link

conditional block variable isset check. #327

Open smarchint opened 7 years ago

smarchint commented 7 years ago

in #284, the discussion was ended with a context object as parameter for the mustache_engine's render function. I have a follow up.

How to handle this case ? $m->render("{{#a}}{{b}}{{/a}}", new ThrowyThing(['b' => ['d' => 'E']]));

Chemaclass commented 6 years ago

Well, if $a is not define I guess the condition will be false, so nothing will be render there. Neither an Exception, isn't it?

smarchint commented 6 years ago

@Chemaclass As per the issue #284 , the objective is to throw an error for undefined variables. So, my concern was how to throw error if the variable is not provided in the context but is in the template as {{#some_block}}. (if block)

Currently with the solution provided in #284, I am getting and exception with $m->render("{{#a}}{{b}}{{/a}}", new ThrowyThing(['b' => ['d' => 'E']]));

smarchint commented 6 years ago

Luckily, I have found this https://github.com/bobthecow/mustache.php/pull/325. Waiting for this to get merged. @bobthecow

Chemaclass commented 6 years ago

@SaikumarChintada Nice one!

kitepwr commented 5 years ago

It's been 2 years and it doesn't look like [#325]() got merged.
Is there another feature that accomplishes this (if so what would that be)? Thx!