Comments (1)
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)
- Not working after glr merge HOT 4
- Test fails on Windows as of 2016.11 HOT 3
- Build fails on Rakudo 2017.3-232-gfbc6697
- Template Mustache is test fails while installing Bailador HOT 1
- Template::Mustache fails to install/recognize dependencies HOT 3
- The digit 0 doesn't print HOT 1
- Tag names can only contain what is considered an <ident> HOT 1
- Content of section tags spills out HOT 2
- Triple Mustache doesn't work when the field name contains a minus HOT 2
- Failing to install with Rakudo master HOT 2
- Inheritance templates HOT 5
- Speed problems HOT 7
- Doubt about Mustache specification HOT 6
- Cannot install Template::Mustache with rakudo 2019.11 HOT 1
- Allow HTML escaping to be disabled HOT 1
- Can't install Template::Mustache HOT 2
- Crash when parallel render; not thread safe? Dies with X::HyperRace::Died in test case HOT 7
- Fails to install on windows HOT 2
- deprecation warning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raku-template-mustache.