nice framework! two questions: dom selector and th:with

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

nice framework! two questions: dom selector and th:with

corey
Nice framework so far.

I have two questions to test my proof of concept:

1)  How do I use a dom selector as a list in a th:each such that I can select all fragments within a file and iterate them?

th:each="scripts : scriptsfile :: [//script]"



2)  How do I use the th:with properly within a substituteby/include? Thymeleaf is not using the variable and is trying to find the variable name instead. (template1 fails.. template2 works)

<div th:with="fragDir=${fragmentsDirectory}+'widget1'">

        <script th:fragment="template1" id="template1" type="text/javascript"> <div th:substituteby="${fragDir}"></div> </script>       
        <script th:fragment="template2" id="template2" type="text/javascript"> <div th:substituteby="${fragmentsDirectory}+'widget1'"></div> <div th:substituteby="${fragmentsDirectory}+'widget2'"></div> </script>       
</div>
Reply | Threaded
Open this post in threaded view
|

Re: nice framework! two questions: dom selector and th:with

Emanuel
Administrator
For #1, you won't be able to do that with any of the standard Thymeleaf attribute processors.  You'll need to develop an your own attribute processor in an extension ("dialect" in Thymeleaf speak) to do that.

For #2, is fragDir the name of a template?  th:substituteby uses the following syntax:

th:substituteby="template_name [:: fragment_name]"  (template_name required, fragment_name optional with a :: separating the 2)

template_name should end-up referring to an HTML file, and if you don't specify a fragment_name, then the entire file will replace the th:substituteby tag.