Handlebars.JS (w/ Dashbars) parse error “expecting open_endblock got inverse”

限于喜欢 提交于 2019-12-12 06:13:56

问题


First, I dumped the output that's going to the Handlebars template and ran it through JSONlint.com and it validates, so my inputs are valid. Second, this is the best example code I could cook up that's representative but doesn't include vital data: http://codepen.io/Muzical84/pen/BNBLom?editors=101 (note, if you have HTTPS-Everywhere on, turn it off on codepen.io since the support is listed as "partial," and Chrome might still bark about unsafe scripts; I included all of the libraries besides jQuery, minified, in the bottom of the JS portion in order to shut up dev tools as much as I could.) I'll also be including some of the code below because SO is telling me that it won't let me include that link otherwise.

Anyway, I'm trying to use Handlebars with a side of Dashbars to output the results of a ColdFusion WSDL. It was working on a Friday afternoon, but then when I started working on code last Monday, everything I do yields this error:

     Uncaught Error: Parse error on line 139:
     ...                    {{else}}           
     -----------------------^
     Expecting 'OPEN_ENDBLOCK', got 'INVERSE'

The code at that point is:

<td><p>{{#each phoneObj}}
                    {{#if (s-start-with? 'Y' PRIMARY_FLAG)}}
                        <span class="primaryInformation">{{PHONE}}</span>
                            <span class="lightBlue">
                                {{#if COMM_LOCATION_CODE}}
                                    {{COMM_LOCATION_CODE}}
                                {{else}}
                                    {{PHONE_TYPE}}
                                {{/if}}
                            </span>
                    {{else}}
                        {{PHONE}}
                        <span class="lightBlue">
                            {{#if COMM_LOCATION_CODE}}
                                {{COMM_LOCATION_CODE}}
                            {{else}}
                                {{PHONE_TYPE}}
                            {{/if}}
                        </span>
                    {{/if}}
                    <br />
                {{else}}
                    No phone or e-mail data found
                {{/each}}</p>
            </td>

(I apologize for formatting...) The phone data (which is actually phone and/or e-mail; I didn't design this database...) is roughly half-way between the ends of the template that are in my codepen.io example. (The whole thing is really long and I didn't want to waste anyone's time with the whole, long thing.) Originally, I was doing more {{#if fieldThatShouldHaveData}} {{else}} but took that out for debugging purposes.

At first, I had named the object "phone" and thought that maybe "phone.PHONE" was too ambiguous, but "this.PHONE" and renaming it to phoneObj didn't change anything. This is all within a huge {{#each this}} that prints the rows of the table. I'm not using any tags that I don't use earlier in the template without incident, and I did confirm that it's legal for me to nest if's and etc.

Incidentally, even if I comment out those lines with {{! if xyz}} I still get the same error, citing the same line.

I'm also having the problem of my outermost {{#each}} looping in such a way that only the last record returned is being output through the template. Everything logs in {{log this}} after that opening {{#each}} , but it's not even hiding in the HTML output somewhere.

I AM new to templating, so those of you who've done it before may think this is a stupid question. I've done what I can with the documentation available, but much of the handlebars official documentation seems to presume familiarity with templating.


回答1:


It turned out that the line cited by the error message was wrong, (probably because, when I was looking for the line number in my my code file, I was forgetting to add the lines from the head template from my <cfinclude> at the top. I'm still new enough to ColdFusion that...that happens...) Further on down, I DID have a missing {{/if}} I'm not sure why the lines were being cited that were, but there it is. However, my "each only prints the last item" bug persists, but I'll create a different question for that.



来源:https://stackoverflow.com/questions/29754153/handlebars-js-w-dashbars-parse-error-expecting-open-endblock-got-inverse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!