title: Having Mustache templates both render and not, with Laravel/Blade and JavaScript
body: <p>I'm using Laravel and all my templates are using Blade templating. There are a few parts of pages which need to be rendered both on the server side and by JavaScript. For these I'm using Mustache templates (with <a href="https://github.com/conarwelsh/mustache-l4" rel="nofollow noreferrer">mustache-l4</a>).</p>
  
  <p>The problem is how to have Laravel render the templates, but also to include them in the page with the Mustache tags intact, for the JS to pick up.</p>
  
  <p>For example, if I have a (simplified example) Blade template like this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;{{ $pageTitle }}&lt;/h1&gt;
      @include('partials/'.$partialName, array('some_text' =&gt; $pageText))
  
      &lt;script type="text/mustache"&gt;
          @include('partials/'.$partialName)
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>which includes <code>.mustache</code> partials like this:</p>
  
  <pre><code>{{#some_text}}
      &lt;p&gt;{{some_text}}&lt;/p&gt;
  {{/some_text}}
  </code></pre>
  
  <p>The Mustache partial is rendered on page load fine. BUT when it's included between the <code>&lt;script&gt;&lt;/script&gt;</code> tags I want it to be rendered verbatim. ie, the <code>{{#some_text}}</code> Mustache tags should be there in the rendered HTML. Then the JavaScript can read it in as a Mustache template.</p>
  
  <p>I can see this might be possible by <a href="https://stackoverflow.com/questions/13944623/escape-double-braces-in-mustache-template-templating-a-template-in-n">changing the tag delimiters on the server-side (Blade) templates</a> but at this stage, with scores of Blade templates already working, I'd rather not.</p>
  
  <p>I can't get my head round how to do this. Could I change the Mustache delimiters just for one of the times it's included, so it's only fully rendered then?</p>