Crow icon indicating copy to clipboard operation
Crow copied to clipboard

Mustache lambda support doesn't follow spec

Open jake-arkinstall opened this issue 1 year ago • 0 comments

According to https://mustache.github.io/mustache.5.html, a lambda should be invoked as follows:

{{#wrapped}} {{name}} is awesome. {{/wrapped}}

This would first evaluate name (in their example "Willy"), and then result in wrapped("Willy is awesome")

In the Crow implementation, lambas are called using normal tags, not as a block. As a result, there is no mechanism to pass a value to them. Even though the lambda signatures must be string(string), the parameter is always given as an empty string.

One way I use the lambda feature is to allow a template to provide content as markdown (how it is stored), or for it to output content as HTML using md4c. As the markdown conversion is not at zero cost, I only want to provide this representation if and when the template requires it. For instance, an edit form would provide the markdown version, whereas a normal view would provide the HTML converted version.

An ideal template for me would be:

{#markdown_to_html}
   {{summary}}
{/markdown_to_html}

{#markdown_to_html}
   {{content}}
{/markdown_to_html}

Whereas at the moment, I have to provide two functions, summary_html and content_html, which disregard their argument and produce the converted value upon demand.

jake-arkinstall avatar Mar 30 '23 15:03 jake-arkinstall