<p>Twig output tags won't work inside of Twig output tags.</p>

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

<p>The overall approach seems a bit heavy-handed though.</p>

CC BY-SA 3.0
2018-04-19T09:22:38.817Z
You beat me to it by 7 secs :(
carlcs
CC BY-SA 3.0
2018-04-19T09:25:19.167Z
I'll remember this next time you beat me :)
Andris Sevcenko
CC BY-SA 3.0
2018-04-19T09:21:37.930Z
2018-04-19T09:21:37.930Z
Andris Sevcenko
<p>You are using <code>{{ ... }}</code> echo syntax within <code>{{ ... }}</code> to return a variable. Use string concatenation instead:</p>

<pre><code>'&lt;span class="remark__label"&gt;' ~ loop.index ~ '&lt;/span&gt;'
</code></pre>

CC BY-SA 3.0
2018-04-19T09:29:09.440Z
Yes, this is how the numbering works, but it does not work, it gives out 1 1 1 1
paveell
CC BY-SA 3.0
2018-04-19T09:43:23.473Z
`loop.index` not returning what you want is a different issue. Can you open a new question where you share the code including your for-loops please (and leave out all irrelevant things like replace filters)?
carlcs
CC BY-SA 3.0
2018-04-19T10:22:53.337Z
Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field
paveell
CC BY-SA 3.0
2018-04-19T09:21:44.943Z
2018-04-19T09:21:44.943Z
carlcs
<p>Good day!</p>

<p>In <strong>Craft CMS 3</strong>, I'm tring to configure the replacement of tags for markdown via replace, everything works except for the tag <code>{{ loop.index }}</code> </p>

<p>Please tell me how to properly configure to work correctly <code>{{ loop.index }}</code>?</p>

<pre><code>{{ block.markdownContent|markdown

 |replace('&lt;p&gt;', '&lt;p class="section__paragraph text"&gt;')
 |replace('&lt;h2&gt;', '&lt;h2 class="section__title title"&gt;')
 |replace('&lt;a ', '&lt;a class="link link-color"')
 |replace('&lt;ul&gt;', '&lt;ul class="attention"&gt;')
 |replace('&lt;li&gt;', '&lt;li class="attention__item"&gt;&lt;p class="attention__text"&gt;')
 |replace('&lt;/li&gt; ', '&lt;/p&gt;&lt;/li&gt;')
 |replace('&lt;ol&gt;', '&lt;ol class="remark list"&gt;')
 |replace('&lt;li&gt;', '&lt;li class="remark__item item"&gt;&lt;p class="remark__text"&gt;&lt;span class="remark__label"&gt;{{ loop.index }}&lt;/span&gt;')
 |replace('&lt;/li&gt; ', '&lt;/p&gt;&lt;/li&gt;')|raw }}
</code></pre>

<p>Can you advise other ways of realizing this task.</p>

CC BY-SA 3.0
2018-04-19T09:18:06.050Z
`{{ loop.index }}` is usually part of Twig language. I'm not sure why/how you are going to change the syntax of the language, More important: why does your field contains Twig Syntax in the first place?
Robin Schambach
CC BY-SA 3.0
2018-04-19T09:23:04.030Z
Can there be a more correct solution to the problem?
paveell
CC BY-SA 3.0
2018-04-19T11:39:05.660Z
Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field
paveell
<templating>
Why does loop.index not work with replace?
# Why does loop.index not work with replace?

(Asked by: username_0 on 2018-04-19)

Good day!
In Craft CMS 3, I'm tring to configure the replacement of tags for markdown via replace, everything works except for the tag {{ loop.index }} 
Please tell me how to properly configure to work correctly {{ loop.index }}?
{{ block.markdownContent|markdown

 |replace('', '')
 |replace('', '')
 |replace('', '')
 |replace('', '')
 |replace(' ', '')
 |replace('', '')
 |replace('', '{{ loop.index }}')
 |replace(' ', '')|raw }}

Can you advise other ways of realizing this task.

**Tags:** templating
> **Comments:**
> **username_1**: `{{ loop.index }}` is usually part of Twig language. I'm not sure why/how you are going to change the syntax of the language, More important: why does your field contains Twig Syntax in the first place?  
> **username_0**: Can there be a more correct solution to the problem?  
> **username_0**: Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field  

---

## 2 answers

### Answer by username_2 on 2018-04-19. Score: 2

Twig output tags won't work inside of Twig output tags.

You should be using `'- '~loop.index~''`

The overall approach seems a bit heavy-handed though.

> **Comments:**
> **username_3**: You beat me to it by 7 secs :(  
> **username_2**: I'll remember this next time you beat me :)  

---

### Answer by username_3 on 2018-04-19. Score: 2

You are using {{ ... }} echo syntax within {{ ... }} to return a variable. Use string concatenation instead:
'' ~ loop.index ~ ''

> **Comments:**
> **username_0**: Yes, this is how the numbering works, but it does not work, it gives out 1 1 1 1  
> **username_3**: `loop.index` not returning what you want is a different issue. Can you open a new question where you share the code including your for-loops please (and leave out all irrelevant things like replace filters)?  
> **username_0**: Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field  

---

