• Resolved spasibych

    (@spasibych)


    Plugin version: 1.4.2

    Templates type: script type=text/plain

    Simple source example
    <script type="text/plain" template="amp-mustache"> <i>t</i> <b>a</b> <div>g</div> </script>

    Output after processing
    <script type="text/plain" template="amp-mustache"> <i>t <b>a <div>g </script>

    Is there a way to prevent this behavior?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    What happens if you instead use <template type="amp-mustache">...</template>?

    Thread Starter spasibych

    (@spasibych)

    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.

    Plugin Author Weston Ruter

    (@westonruter)

    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>
    Thread Starter spasibych

    (@spasibych)

    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.

    Plugin Author Weston Ruter

    (@westonruter)

    @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?

    Plugin Author Weston Ruter

    (@westonruter)

    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.

    Thread Starter spasibych

    (@spasibych)

    @westonruter yes, exactly.

    Everything works fine on the site, but everything breaks in Google AMP Cache, because commented tags disappear.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘In mustache templates are removed all closing tags’ is closed to new replies.