mmikkel / Retcon-Craft

A collection of powerful Twig filters for modifying HTML
MIT License
80 stars 9 forks source link

Injecting as a 'prepend' #23

Closed mikefats closed 2 years ago

mikefats commented 4 years ago

Is there a trick to inject something before existing content? https://github.com/mmikkel/Retcon-Craft/wiki/Inject If not, then maybe it could be considered for implementation?

mmikkel commented 4 years ago

Sorry, not that I can think of – and the retconInject filter doesn't support prepending.

I'll label this as a feature request, for now :)

mikefats commented 4 years ago

I might as well ask – here's what I'm trying to solve with retcon:

I'm rendering a <ul><li> list of items, and would like to retconInject a _font awesome_ icon for each <li>, so
<li> …list content …</li>
becomes
<li><i class="far fa-check-circle"></I> …list content …</li>

Not do-able, right?

superpikar commented 3 years ago

@mikefats I have a similar problem, as a workaround, you can achieve the same result by using |replace filter

yourString|replace('<li>', '<li><i class="far fa-check-circle"></i>')
mmikkel commented 2 years ago

Looked into this, but ended up deeming it "not worth the effort". For simple stuff the |replace filter does the job, another alternative is to use CSS (flexbox or position: absolute) to change the visual order of injected nodes.