Append/Prepend text attributes
See original GitHub issueAccording to this question at SO it would be nice to have attributes to append/prepend text.
Reasons:
- Using inline text would destroy the idea of prototyping
- Using
th:remove="tag"
would add html elements which aren’t necessary - Using
<!--/*/<th:block th:text="'Hello Thymeleaf'">/*/-->Hello world<!--/*/</th:block>/*/-->
isn’t good practice and would bloat the code unnecessarily
Ideas:
th:textappend="'Hello world'"
would append textth:textprepend="'Hello world'"
would prepend text
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Element.prepend() - Web APIs - MDN Web Docs
The Element.prepend() method inserts a set of Node objects or string objects before the first child of the Element.
Read more >Append and prepend text | Web Scraper Documentation
Prepend text - add text at the beginning of the string. Text to place - text that will be placed. Escape sequences as...
Read more >Prepending Elements - JavaScript Tutorial
The prepend() method inserts DOMString objects as Text nodes. Note that a DOMString is a UTF-16 string that directly maps to a string....
Read more >jquery - Append text to an attribute rather than replacing it?
$('.theclass').attr('title', (i, value) => `${value || ""}appended text`);. i is the index of the attribute, value is the current value of the attribute......
Read more >.prepend() | jQuery API Documentation
DOM element, text node, array of elements and text nodes, HTML string, or jQuery object to insert at the beginning of each element...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I understand, and actually I’ve seen myself in this situation several times (working with Bootstrap buttons, for example). I’ve always solved this with inlining, but I understand why someone would prefer to do it in a prototype-friendly manner.
I’m adding this therefore to the Wishlist, but with a modification: the idea should be to have something more general than simply making text be a prefix or a suffix of the existing body of the tag. Adding two new attributes to the standard dialect just for having prefixes and/or prefixes seems a bit too much burden for features that would be a bit limited for solving this kind of scenarios.
The first idea that comes to my mind is to create some kind of syntax that might allow specifying which parts of the body should be replaced, maybe based on or related to the markup selector syntax, something like
/text()[0]: ${whatever}
.However, this could get a bit in the way of Fragment Expressions… maybe using fragment expressions themselves could help, without the need to create new syntaxes?.. I don’t know. Or maybe we could be talking about adding functionality to
th:replace
(to select the specific part of the body that should be replaced) instead ofth:text
…Also, from the standpoint of the engine, something like this would probably mean some deep changes in
ProcessorTemplateHandler
, because there is currently no command that can be given to structure handlers to provoke a complex substitution of body events like this…If this doesn’t end up on the to-do list for Thymeleaf, then this idea might be a really good custom dialect & processor for someone to make.