Replies: 2 comments
-
hi @pdaoust, currently it's not possible to use function as data field directly in handlebars-rust. Because internally we transformed all data into serde_json's I will suggest you to filter |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the response. I ended up creating a |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm working on someone else's code, and the context passed into one template (let's call it a
Bar
) contains one propertyfoos
which is aVec<Foo>
. EachFoo
has a propertywidget
which is used to filter in some{{#each}}
blocks but not others. It'd be no problem if the template were simply generating content like this:{{#each foos}}{{#if widget}}<p>{{name}}</p>{{/if}}{{/each}}
, but in some cases it's used to create a comma-separated list:As you can see, if the second-to-last
foo
is awidget
, but the last one is not, there'll be a trailing comma, which causes the generated file to be invalid (it's generating JS code).I'd like to avoid creating a new
foos_that_are_widgets
field on the context, so I'm wondering if it's possible to either:foos_that_are_widgets()
function in theimpl
forBar
that returns the filtered vecfoos
during or before{{#each}}
Beta Was this translation helpful? Give feedback.
All reactions