question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Append/Prepend text attributes

See original GitHub issue

According 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 text
  • th:textprepend="'Hello world'" would prepend text

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielfernandezcommented, Nov 3, 2016

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 of th: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…

0reactions
ultraqcommented, Nov 2, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found