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

Commenting out expressions doesn't work as expected #65

Open
jslegers opened this issue Jul 2, 2014 · 4 comments
Open

Commenting out expressions doesn't work as expected #65

jslegers opened this issue Jul 2, 2014 · 4 comments

Comments

@jslegers
Copy link
Contributor

jslegers commented Jul 2, 2014

It's unclear to me whether it's possible to comment out expressions and have handlebars.php completely ignore anything in a comment, which is possible in pretty much every programming language and commonly used for temporarily storing deleted code that may be fully or partially restored at a later time.

Currently, handlebars.php tries to parse any {{ }} it can find as an expression, including those within comments. This results in a fatal error when no helper can be found with that name.

That means I can't do this :

<!--
<html>
    <body>
        Hello {{name}}</br>
        You have just won ${{value }}!</br>
        {{#in_ca}}
        Well, ${{taxed_value}}, after taxes.</br>
        {{/in_ca}}
    </body>
</html>
-->

This also doesn't work :

{{!-- comment}}
<html>
    <body>Hello {{name}}</br>
        You have just won ${{value}}!</br>
        {{#in_ca}}
        Well, ${{taxed_value}}, after taxes.</br>
        {{/in_ca}}
    </body>
</html>
{{comment --}}

This doesn't work either :

{{!--
<html>
    <body>Hello {{name}}</br>
    You have just won ${{value}}!</br>
    {{#in_ca}}
    Well, ${{taxed_value}}, after taxes.</br>
    {{/in_ca}}
    </body>
</html>
--}}

Neither does this :

{{!-- <html><body>Hello {{name}}</br>You have just won ${{value}}!</br>{{#in_ca}}</br>Well, ${{taxed_value}}, after taxes.{{/in_ca}}</body></html> --}}

Whatever I try, I keep getting the following error :

<b>Fatal error</b>:  Uncaught exception 'RuntimeException' with message 'in_ca is not registered as a helper' in /var/www/monitoring/Vendor/Handlebars/Template.php:349
Stack trace:
#0 /var/www/monitoring/Vendor/Handlebars/Template.php(404): Handlebars\Template-&gt;_mustacheStyleSection(Object(Handlebars\Context), Array)
#1 /var/www/monitoring/Vendor/Handlebars/Template.php(162): Handlebars\Template-&gt;_section(Object(Handlebars\Context), Array)
#2 /var/www/monitoring/Vendor/Handlebars/Handlebars.php(173): Handlebars\Template-&gt;render(Object(Application\View_Model))
#3 /var/www/monitoring/dashboard.php(46): Handlebars\Handlebars-&gt;render('&lt;!DOCTYPE html&gt;...', Object(Application\View_Model))
#4 {main}
  thrown in <b>/var/www/monitoring/Vendor/Handlebars/Template.php</b> on line <b>349</b><br />

This isn't how I expect comments to work.

@DavideMontersino
Copy link

I think that {{!-- }} comments are not supported at all; only {{! expression }} style comments are supported.

I think this should be implemented in src/Handlebars/Tokenizer.php.. if I have time to study the library I'll fix that!

@JustBlackBird
Copy link
Contributor

@jslegers the original comments syntax is {{! This is a comment }}. Moreover a comment cannot contain closing stashes (}}).

In your last example anything after the first }} token is treated as a template, not as a comment. I think that you have not registered in_ca helper, that's why you've got an exception.

I believe that Handlebars.php behavior is correct and correspond to Handlebars.js behavior.

@primehalo
Copy link

Handlebars.js allows comments that contain handlebar tokens with the {{!-- --}} syntax, and looks like that functionality has been there since at least 2013. Has this still not been implemented in Handlebars.php?

@jcubic
Copy link

jcubic commented Sep 9, 2016

+1 for comments.

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

5 participants