ultraq / thymeleafjs

A basic implementation of the Thymeleaf templating engine in JavaScript
Apache License 2.0
52 stars 8 forks source link

Parameterizable fragment signatures #50

Open devowhippit opened 7 months ago

devowhippit commented 7 months ago

I've greatly appreciated this implementation and being able to get to know Thymeleaf. Thank you so much! Noting the following as either a question; am I doing something wrong? or is it possible to support?

I've succeeded with the library using the first argument format option described in parameterizable fragment signatures.

<th:block th:replace="~{path/to/fragment :: fragment(${value1}, ${value2})}">

However, the second parameter option is more desirable but I have not had success using it.

<th:block th:replace="~{path/to/fragment :: fragment(onevar=${value1}, twovar=${value2})}">

Many thanks!

ultraq commented 7 months ago

Hey there 👋 Sorry, it's been a while since I really looked into this project and the parsing code, but it looks like the second option isn't implemented hence the inability for you to use it with this library.

For anybody interested, the fragment expression definition is mostly in this block of code: https://github.com/ultraq/thymeleafjs/blob/2f9693736f4faefd6a311559c8352956e2bc6470/source/standard/expressions/ThymeleafExpressionLanguage.js#L168C5-L209 From it, you can see that a fragment expression's "FragmentParameters" are a list of "Expression" rules, nothing in there about like "NameAndExpression" rule which would then be used to read the second syntax.

It doesn't look like there's an existing issue for it (the one saying what syntaxes are supported just says that fragment expressions are supported but doesn't break it down into the various types), so I'll leave this open to track that.