xmlet/HtmlFlow

Story for generating inline css or inline js

benzen opened this issue · 4 comments

Does this project plan to produce inline js or inline css.

Using thymleaf it happens from time to time that I need to produce in my inline js base on some variable extracted from the model.

Can you give an example use case please, for that usage.

I'll use the exemple provided in the thymleaf documentation

<script th:inline="javascript">
    ...
    var username = [[${session.user.name}]];
    ...
</script>

Here the value from session.user.name is used to generate the content of the script.

There is ways to workarround this as a missing feature, like adding data to the dom, that the JS code would pick up on initialisation.

But the way proposed by thymleaf feels quite natural to me. If we decide to not provide support for this feature in HtmlFlow, I think documentation should guide a developper toward alternatives.

Maybe I am not entirely understanding that use case. But I am not figuring out the need of "adding data to the dom, that the JS code would pick up on initialisation".

If I am thinking well when you build a Javascript block in HtmlFlow such as: ....script().text(inlinejs), where the inlinejs local variable should be initialized before with the Js code such as String inlinejs = String.format("... var username = %s", session.user.name). Isn't it?

This is perfect, especially with brand new textblock feature and the instance method formatted on string.

As I suspected it's just a matter of documentation. Thank you very much.

I propose we keep this issue open, I'll make a PR for enhancing documentation on this point