Answers.Body: <p>If you need to do something like the image below. The best option is to set the content as a variable and use the <code>replace()</code> filter to replace the tokens tags. Finally, use <code>autoescape</code> pair tag to output the content.</p>
  
  <p>Not an elegant solution, but it works for me ;)</p>
  
  <pre><code>{# #############
          Field names
          -----
          Body: f_body
          Assets:
              f_media
                  position
                  media (assets)
  ############# #}
  
  
  {% block content %}
  
      {% set body = entry.f_body|raw %}
  
      {% for item in entry.f_media %}
          {% if item.type == 'assets' %}
              {% set name = '{image_' ~ loop.index ~ '}' %} # name of token to replace
              {% set image = item.media[0].getUrl() %} # image path
              {% set imageElement = '&lt;img src="' ~ image ~ '" class="' ~ item.position ~ '" /&gt;'  %} # image element
  
              {% set body = body|replace(name, imageElement) %}
          {% endif %}
      {% endfor %}
  
  
      {% autoescape false %}
          {{ body }}
      {% endautoescape %}
  
  {% endblock %}
  </code></pre>
  
  <p>ps: This is something I came up quickly, needs bit of refactoring obvs.</p>
  
  <p><a href="https://i.sstatic.net/EwbMt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EwbMt.png" alt="Image replacement technique"></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-07T21:50:49.513Z
Answers.Text: Late to the party boss ;)
Answers.UserDisplayName: Dimitri Kouvdis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-09T15:28:58.730Z
Answers.Text: what a legend! boom
Answers.UserDisplayName: Richard Frank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-07T21:44:36.167Z
Answers.LastActivityDate: 2017-11-10T16:57:12.977Z
Answers.LastEditDate: 2017-11-10T16:57:12.977Z
Answers.UserDisplayName: Dimitri Kouvdis
Answers.Body: <p>This generally isn't necessary in Craft. You can use a Matrix Field and combination of Matrix Blocks to build advanced content with flexible images. This is really the best way to go if it's an option.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-26T16:10:00.307Z
Answers.LastActivityDate: 2014-07-26T16:10:00.307Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I'd like to use a tokenised image replacement technique which is commonly adopted in ExpressionEngine. This is where the author can add image tokens such as {image_1}, {image_2} etc into their content, and these get replaced by images defined in a matrix in the same publish form (with additional information such as image size etc). What technique can I use to achieve this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-26T15:02:55.030Z
Comments.Text: This generally isn't necessary in Craft. You can use a Matrix Field and combination of Matrix Blocks to build advanced content with flexible images.  This is really the best way to go if it's an option.  That said, if you really needed what you've described, you could possibly do so with outputting your Rich Text field with Twig's template_from_string function and looping through your tokens field with the replace filter or something like that. I'm not posting this as an answer as I haven't tested this.
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-26T15:29:32.297Z
Comments.Text: @Ben the Matrix part of your comment alone is worth an actual answer, that I'd tag as accepted if this was my question.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-26T16:10:16.470Z
Comments.Text: Ok @ChristianSeelbach, you talked me into it =)
Comments.UserDisplayName: Ben Parizek
Tags: <assets><matrix>
Title: How to integrate an image haystack replacement technique
ThreadText: # How to integrate an image haystack replacement technique
  
  (Asked by: username_0 on 2014-07-26)
  
  I'd like to use a tokenised image replacement technique which is commonly adopted in ExpressionEngine. This is where the author can add image tokens such as {image\_1}, {image\_2} etc into their content, and these get replaced by images defined in a matrix in the same publish form (with additional information such as image size etc). What technique can I use to achieve this?
  
  **Tags:** assets, matrix
  
  > **Comments:**
  > **username_1**: This generally isn't necessary in Craft. You can use a Matrix Field and combination of Matrix Blocks to build advanced content with flexible images.  This is really the best way to go if it's an option.  That said, if you really needed what you've described, you could possibly do so with outputting your Rich Text field with Twig's template_from_string function and looping through your tokens field with the replace filter or something like that. I'm not posting this as an answer as I haven't tested this.  
  > **username_2**: @Ben the Matrix part of your comment alone is worth an actual answer, that I'd tag as accepted if this was my question.  
  > **username_1**: Ok @ChristianSeelbach, you talked me into it =)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-11-07. Score: 3 | Accepted answer
  
  If you need to do something like the image below. The best option is to set the content as a variable and use the `replace()` filter to replace the tokens tags. Finally, use `autoescape` pair tag to output the content.
  
  Not an elegant solution, but it works for me ;)
  
  ```
  {# #############
          Field names
          -----
          Body: f_body
          Assets:
              f_media
                  position
                  media (assets)
  ############# #}
  
  {% block content %}
  
      {% set body = entry.f_body|raw %}
  
      {% for item in entry.f_media %}
          {% if item.type == 'assets' %}
              {% set name = '{image_' ~ loop.index ~ '}' %} # name of token to replace
              {% set image = item.media[0].getUrl() %} # image path
              {% set imageElement = '<img src="' ~ image ~ '" class="' ~ item.position ~ '" />'  %} # image element
  
              {% set body = body|replace(name, imageElement) %}
          {% endif %}
      {% endfor %}
  
      {% autoescape false %}
          {{ body }}
      {% endautoescape %}
  
  {% endblock %}
  
  ```
  
  ps: This is something I came up quickly, needs bit of refactoring obvs.
  
  [![Image replacement technique](https://i.sstatic.net/EwbMt.png)](https://i.sstatic.net/EwbMt.png)
  
  > **Comments:**
  > **username_3**: Late to the party boss ;)  
  > **username_0**: what a legend! boom  
  
  ---
  
  ### Answer by username_1 on 2014-07-26. Score: 6
  
  This generally isn't necessary in Craft. You can use a Matrix Field and combination of Matrix Blocks to build advanced content with flexible images. This is really the best way to go if it's an option.
  
  
  ---
  
  