Coder Social home page Coder Social logo

Comments (1)

softmoth avatar softmoth commented on August 28, 2024

OK, I believe I found the problem with this test case. The category needs to be wrapped in a hash; as it is, categories is an array of two items. The first item (:category_pages([...])) gets applied to the template. It has no <title>, so {{title}} is null. It does have <category_pages>, so {{#category_pages}} section is expanded properly.

The second item is :title("General tasks"). So this time through {{#categories}} it fills in {{title}}, but the {{#category_pages}} section becomes null.

It took me a long time to figure this out, because the following does not wrap a hash around it as I'd expected:

my %h = categories => [
  {
    category_pages => [
       {title => "Perl 6",
        url   => "https://www.perl6.org"},
       {title => "Perl 6 Modules",
        url   => "https://modules.perl6.org"}],
    title => "General tasks"
  }
];

I'm a a few years behind on P6 syntax and it appears that [ { foo => bar } ] flattens the {} out. I'm sure there's a good reason for it. It needs a comma at the end to force it to keep the hash. So the following works as desired:

my %h = categories => [
    {
        title => "General tasks",
        category_pages => [
            { title => "Perl 6", url => "https://www.perl6.org" },
            { title => "Perl 6 Modules", url => "https://modules.perl6.org" },
        ],
    },
];

my $html = q:to/EOF/;
{{#categories}}
{{ title }} <!-- should be first item -->
{{#category_pages}}
{{ title }} : {{ url }}</br>
{{/category_pages}}
{{/categories}}
EOF

is Template::Mustache.render($html, %h),
    q:to/EOF/,
    General tasks <!-- should be first item -->
    Perl 6 : https://www.perl6.org</br>
    Perl 6 Modules : https://modules.perl6.org</br>
    EOF
    ;

from raku-template-mustache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.