What happens if you instead use <template type="amp-mustache">...</template>
?
I need to output tables and I used a wrapper <!– {{#bar}} –> along with a <template> that once worked perfectly. See amp-mustache/#tables
But now there is a problem with Google AMP Cache – in cache templates, the <!– {{#bar}} –> tags disappear (i see it through browser DOM viewer), although everything works without errors on the site.
While I saw the opportunity to quickly fix the situation through the script type = text/plain templates (they work in the cache), but now there is a problem with the plugin.
Thanks for reporting this. You’re absolutely right. This is a bug in the plugin. I’ve opened this issue to address: https://github.com/ampproject/amp-wp/issues/4254
However, there is another workaround mentioned in the AMP docs. Namely, you can use HTML comments to prevent the broken markup while using the <template>
tag.
So instead of:
<script type="text/plain" template="amp-mustache">
<table>
<tr>
{{#foo}}<td></td>{{/foo}}
</tr>
</table>
</script>
Please try this workaround instead:
<template type="amp-mustache">
<table>
<tr>
<!--{{#foo}}--><td></td><!--{{/foo}}-->
</tr>
</table>
</template>
Thank you for your attention to the problem.
Unfortunately, this will not help me now because of the problem with Google AMP Cache, which i described in the previous comment and in this issue https://github.com/ampproject/amphtml/issues/26656.
Actually, i was forced to use script[type=text/plain]
due to a problem with <!--{{#foo}}-->
in Google AMP Cache.
@spasibych I see. So the AMP Cache is performing an optimization which is stripping all HTML comments, but this ends up breaking the workaround for using Mustache templates for tables. Is that right? When looking at the AMP page on your site (and not the AMP Cache) the workaround then works as expected?
I was able to reproduce the issue you reported. Details provided here: https://github.com/ampproject/amphtml/issues/26656#issuecomment-583702651
Let’s continue on that issue and also on the AMP plugin one: https://github.com/ampproject/amp-wp/issues/4254
I’ll resolve this topic so discussion can continue on the issues.
@westonruter yes, exactly.
Everything works fine on the site, but everything breaks in Google AMP Cache, because commented tags disappear.