Why does loop.index not work with replace?
Twig output tags won't work inside of Twig output tags.

You should be using '&lt;li class="remark__item item"&gt;&lt;p class="remark__text"&gt;&lt;span class="remark__label"&gt;'~loop.index~'&lt;/span&gt;'

The overall approach seems a bit heavy-handed though.