softmoth / raku-Template-Mustache

Raku library for the Mustache template format
https://modules.raku.org/dist/Template::Mustache:cpan:SOFTMOTH
Artistic License 2.0
21 stars 19 forks source link

Content of section tags spills out #28

Closed uzluisf closed 5 years ago

uzluisf commented 5 years ago

Perl 6 code snippet:

use Template::Mustache;

my $template = q:to/END/;
<!doctype html>
<html lang="{{ lang }}">
  <head>
    <title>{{ title }}</title>
    <meta charset="UTF-8" />
    {{#css}}
        {{#css}}
        <link rel="stylesheet" href="{{.}}">
        {{css}}
    {{/css}}
  </head>

    <body>
        <div id="___top"></div>

        {{#title}}<h1 class='title'>{{ title }}</h1>{{/title}}
        {{#subtitle}}<p class='subtitle'>{{ subtitle }}</p>{{/subtitle}}

        <div class="content">
        {{#body}}
            {{{ . }}}
        {{/body}}
        </div>
    </body>

</html>
END

my %page = %(
    lang => 'English',
    title => 'New page',
    subtitle => 'From first to last',
    css => ["./github.css"],
    body => [
        "<h1>First heading</h1>",
        '<pre><code>my &sum = -> $x, $y { $x + $y }</code></pre>'
    ],
);

my $output-html = Template::Mustache.render($template, %page);
say $output-html;

Output HTML:

<!doctype html>
<html lang="English">
  <head>
    <title>New page</title>
    <meta charset="UTF-8" />
        <link rel="stylesheet" href="./github.css">
        ./github.css
  </head>

  <body>
      <div id="___top"></div>
      <h1 class='title'>New page</h1>
      <p class='subtitle'>From first to last</p>

      <div class="content">
          <h1>First heading</h1>
          <pre><code>my &sum = -> $x, $y { $x + $y }</code></pre>
      </div>
  </body>

</html>

As you can see, although the CSS filepath was properly included in the {{#css}} ...{{css}} tag, there's also another copy of it hanging out of place in the head section, which ends up showing in the rendered HTML:

image

khalidelboray commented 5 years ago
{{#css}}

        {{#css}} # delete this

        <link rel="stylesheet" href="{{.}}">

        {{css}} # delete this

    {{/css}}

read the manual for more about it

uzluisf commented 5 years ago

That elusive /. Thanks!