Comments (4)
This question is probably best asked on StackOverflow, as this is not a Thymeleaf bug. #arrays.arrayJoin
joins an array into a String with a defined delimiter. In your case hello,world
with the delimiter ,
.
If you want single quotes and square brackets inside said String you will need to add them yourself.
Something like
<div th:data-some-attr="|{ aKey: [${'''' + #arrays.arrayJoin(model.myArray, ''',''') + '''' }] }|">
should probably work. Here is the documentation on how to escape a single quote in SpEL
from thymeleaf.
Maybe this should be a feature request instead?
Tons of different technologies today use "templated javascript" driven by attributes, like htmx
, vue
, alpine
etc..
None of these use inline script tags. Would it be so terrible to add a #arrays.toJSArray()
?
i cant in any shape of form call this modern :P More like 2005..
<div th:data-some-attr="|{ aKey: [${'''' + #arrays.arrayJoin(model.myArray, ''',''') + '''' }] }|">
🤮
<div th:data-some-attr="|{ aKey: ${#arrays.toJSArray(model.myArray)} }|">
🤩
from thymeleaf.
If you have a Jackson ObjectMapper
Bean inside your context (from e.g. Spring Boot); something like <div th:data-some-attr="|{ aKey: ${@objectMapper.writeValueAsString(model.myArray)} }|">
should also work.
Please also have a look at this Stackoverflow post and this one on how to get the ObjectMapper to output single instead of double quotes.
from thymeleaf.
We have used this as a workaround yes, but then we need to use JSON.parse()
on the js side :/
from thymeleaf.
Related Issues (20)
- Switch context lost when using div inside th:case
- Unable to select direct child (using /) HOT 1
- Thymeleaf generated text in TEXT mode replaces CRLF with LF?
- Block to add attributes to included fragments HOT 1
- Do you support CSS3 styles? Like flexbox layout HOT 1
- How to prevent SSTI injection when using hypoleaf in inheriting DispatcherServlet?
- [BUG] using th:field does not work in th:each HOT 1
- GraalVM potential missing reachability metadata
- th:replace by POST response view HOT 1
- BUG: problem with passing Number and String data type to javascript function in thymeleaf looping th:each HOT 3
- Error "Cannot build an application for a request which servlet context does not match with the application that it is being built for." HOT 4
- Cannot use java.util.Currency in expressions
- Migration issue Thymeleaf 3.0.10RELEASE to 3.1.2RELEASE
- when using java 9 modules it doesn't find the template resolver
- Any solution for BDSA-2023-1804? HOT 3
- HTMX integration section in Thymeleaf documentation
- Request for posting of Maven signing key(s) HOT 1
- Replace Variables with issue as empty String HOT 1
- IPostProcessorDialect implementation to minify/remove comments from output html HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thymeleaf.