Using complex th:attr fields with Thymeleaf -
i have thymeleaf template rather complex data- attribute, so:
<div data-dojo-props="required: true, placeholder:'foo bar baz', more: stuff" ...> i'd have thymeleaf provide placeholder, so:
<div th:data-dojo-props="placeholder:'#{foo.bar.baz}'" ...> it doesn't work, of course. i'm supposed use th:attr so:
<div th:attr="data-dojo-props=placeholder:'#{foo.bar.baz}'" ...> which doesn't work. add : or ' within th:attr, template breaks. tried escaping them, e.g. \: , \', , tried using html entities, e.g. &38;, didn't work.
so tried th:prependattr , th:appendattr:
<div th:prependattr="data-dojo-props=placeholder:'" th:attr="data-dojo-props=#{foo.bar.baz}" th:appendattr="data-dojo-props='" ...> but can't handle : , ', nor escaping them:
<div th:prependattr="data-dojo-props=placeholder&58;&39;" th:attr="data-dojo-props=#{foo.bar.baz}" th:appendattr="data-dojo-props=&39;" ...> any way make work i'm missing?
you can use parameters in thymeleaf message property example:
messages.properties:
dojo.props=required: {0}, placeholder: {1}, more: {...} dojo.props.required=true dojo.props.placeholder=foo bar baz html message properties:
<div th:attr="data-dojo-props=#{dojo.props(#{dojo.props.required}, #{dojo.props.placeholder})}"></div> or if want values object:
<div th:attr="data-dojo-props=#{dojo.props(${dojo.props.required}, ${dojo.props.placeholder})}"></div> even selectors work:
<div th:attr="data-dojo-props=#{dojo.props(*{dojo.props.required}, *{dojo.props.placeholder})}"></div>
Comments
Post a Comment