I have a Rust structure that looks something like this:
struct Root{
as: Vec<A>,
}
struct A {
bs: Vec<B>,
cs: Vec<C>,
}
struct B {
strings: Vec<String>,
}
struct C {
strings: Vec<u32>,
}
and i'm trying to get output using Rocket.rs and Handlebars templating.
My handlebars template currently looks like this, but it doesn't work.
{{#each as}}
{{#each bs}}
<h4>{{@index}}</h4>
<pre>{{bs.@index}}</pre>
<pre>{{cs.@index}}</pre>
{{/each}}
{{/each}}
I get the following error Error: Error rendering Handlebars template 'index' Error rendering "index" line 28, col 18: invalid digit found in string, which probably has to do with the @index variables I'm using in the HBS tags.
Is there any other way I could only get one item out of two arrays and place them side-by-side without having to alter my structure?
It is not clear to me what you are trying to achieve. It looks like that for each
AObject in theasArray that you would like to iterate over each element ofbsandcs. This assumes thatbsandcshave the same length for anyA.If this is what you want then I think your problem is that you are trying to access a
csfrom within the context of abs. Within the{{#each bs}}block, the context is the currentBObject. As aBdoes not have acs, you need to step-up a context level so that you return to the context of theAwhich holds thebsand thecs. In Handlebars, you change the context using a path, like../.A simplified template that accesses the
bsand thecsat each index ofbsfor eachAwould be:Note: I used the lookup helper for both the
bslookup and thecslookup for consistency. However, as we are within the context of thebs, we could simply reference it with.. As in:I have created a fiddle for your reference.