-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-mustache: Mustache tags don't work in tables #11205
Comments
Tried this out on the mustache demo and looks like this is WAI. Mustache:
JSON:
Rendered HTML:
Is it possible to use a different variable name for the reply text? I.e. something other |
Hmm, it looks like the Mustache engine itself is working as intended. The second row of the table is correctly not rendered because However, rendering the same Mustache template with the same JSON in AMP HTML (after clicking the button): <amp-list width="auto" height="200" layout="fixed-height" credentials="include"
[state]="comments" src="https://example.com">
<template type="amp-mustache">
<table>
<tr>
<td>Comment:</td>
<td>{{content}}</td>
</tr>
{{#replies}}
<tr>
<td>Reply:</td>
<td>{{content}}</td>
</tr>
{{/replies}}
</table>
</template>
</amp-list>
<button on="tap:AMP.setState({comments: [{content: 'Howdy', replies: []}]})">
Set state
</button> Gives me this: <table role="listitem">
<tr>
<td>Comment:</td>
<td>Howdy</td>
</tr>
<tr>
<td>Reply:</td>
<td>Howdy</td>
</tr>
</table> The second row of the table shouldn't be rendered because Did using the same variable name in the reply text cause this? I can certainly use a different name, but I was under the impression that the |
Sorry, you're right. 😛 Looks like
Not related to AMP code. Investigating. |
The issue is that the browser parses the children of This results in the A workaround is to use elements that have looser semantics, e.g. <template type="amp-mustache">
<div>
<div>
<p>Comment:</p>
<p>{{content}}</p>
</div>
{{#replies}}
<div>
<p>Reply:</p>
<p>{{content}}</p>
</div>
{{/replies}}
</div>
</template> Another method is to support a way to specify a template as an unparsed string, e.g. as a Thanks for reporting this. |
This issue hasn't been updated in awhile. @choumx Do you have any updates? |
I managed to work this out (although in a not very elegant way) by commenting out the section placeholders (so the browser's parser won't foster parent them): <template type="amp-mustache">
<table>
<!-- {{#replies}} -->
<tr>
<td>Reply:</td>
<td>{{content}}</td>
</tr>
<!-- {{/replies}} -->
</table>
</template> |
Another workaround: triple mustache now supports rendering table elements. Closing since there are a few ways to solve this. |
@choumx said:
Further, if there are 2+ span structures nested in That created havoc for elements that are intended to be inline - instead, we get multiple block level output: one for each new |
Re: @jaygray0919's comment, see #17509 (comment). |
What's the issue?
With the following AMP HTML:
I expect the rendered tables to be
Because the first comment in the
comments
state has one item in thereplies
list, but the second comment doesn't.However, the actual rendered tables are
The
{{#replies}}
section is evaluated to the wrong value for the first comment (should beReply: Hi
instead ofReply: Hello
); The{{#replies}}
section is surprisingly evaluated for the second comment even though the second comment has an emptyreplies
list.If I change the template to the following, then the presentation becomes okay (although not quite the DOM structure I was hoping for):
Presentationally this looks the same as my expectation (without table/cell borders), but structurally it renders 3 tables instead of 2.
What browsers are affected?
Only tested on Chrome.
Which AMP version is affected?
Tested with AMP version 1504040004635.
The text was updated successfully, but these errors were encountered: