Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:22:38.817Z
Answers.Text: You beat me to it by 7 secs :(
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:25:19.167Z
Answers.Text: I'll remember this next time you beat me :)
Answers.UserDisplayName: Andris Sevcenko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:21:37.930Z
Answers.LastActivityDate: 2018-04-19T09:21:37.930Z
Answers.UserDisplayName: Andris Sevcenko
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:29:09.440Z
Answers.Text: Yes, this is how the numbering works, but it does not work, it gives out 1 1 1 1
Answers.UserDisplayName: paveell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:43:23.473Z
Answers.Text: `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)?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T10:22:53.337Z
Answers.Text: Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field
Answers.UserDisplayName: paveell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:21:44.943Z
Answers.LastActivityDate: 2018-04-19T09:21:44.943Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-19T09:18:06.050Z
Comments.Text: `{{ 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?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-19T09:23:04.030Z
Comments.Text: Can there be a more correct solution to the problem?
Comments.UserDisplayName: paveell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-19T11:39:05.660Z
Comments.Text: Described the problem here: https://craftcms.stackexchange.com/questions/25754/how-can-i-add-and-replace-classes-in-the-markdown-field
Comments.UserDisplayName: paveell
Tags: <templating>
Title: Why does loop.index not work with replace?
ThreadText: # 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('<p>', '<p class="section__paragraph text">')
   |replace('<h2>', '<h2 class="section__title title">')
   |replace('<a ', '<a class="link link-color"')
   |replace('<ul>', '<ul class="attention">')
   |replace('<li>', '<li class="attention__item"><p class="attention__text">')
   |replace('</li> ', '</p></li>')
   |replace('<ol>', '<ol class="remark list">')
   |replace('<li>', '<li class="remark__item item"><p class="remark__text"><span class="remark__label">{{ loop.index }}</span>')
   |replace('</li> ', '</p></li>')|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 `'<li class="remark__item item"><p class="remark__text"><span class="remark__label">'~loop.index~'</span>'`
  
  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:
  
  ```
  '<span class="remark__label">' ~ loop.index ~ '</span>'
  
  ```
  
  > **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  
  
  ---
  
  