<p>Instead of splitting the content up into multiple fields, you can put your editors in charge of outputting the product headlines by using <a href="https://craftcms.com/docs/3.x/reference-tags.html" rel="nofollow noreferrer">reference tags</a>. So your field content could look like this:</p>
<pre><code>{entry:nike:title}

some text the contenteditor maybe wants do add

{entry:puma:title}

some text the contenteditor maybe wants do add
</code></pre>
<p>In this example, <code>nike</code> and <code>puma</code> would be the entries' slugs. There are other ways to refer to specific entries, check the examples in the documentation linked below.</p>
<p>If I remember correctly, Craft should parse those automatically on output, otherwise you can use the <a href="https://craftcms.com/docs/3.x/dev/filters.html#parserefs" rel="nofollow noreferrer"><code>parseRefs</code> filter</a> in your template.</p>
<p>Another maybe slightly more solid approach would be to use <a href="https://craftcms.com/docs/3.x/matrix-fields.html" rel="nofollow noreferrer">Matrix fields</a>. You can define two block types for product references and custom text respectively. Then loop through them and for every product reference block, output the headline of the selected product as a headline. This would allow your editors more control over the content structure, and you more control over the resulting HTML.</p>

CC BY-SA 4.0
2021-07-18T12:53:16.763Z
2021-07-18T12:53:16.763Z
MoritzLost
<p>The <a href="https://imperavi.com/redactor/plugins/variable/" rel="nofollow noreferrer">Variables</a> plugin in the Redactor plugin might be useful in this case.</p>
<p>One way to handle it would be to create your variables, like Brand and Product.</p>
<p>Setup a Redactor field and add <code>variable</code> to buttons and <code>plugins</code> to the <code>json</code> config. Then inside <code>variables</code> define the variables you want, in this case Brand and Product, for example.</p>
<pre><code>{
  &quot;buttons&quot;: [&quot;html&quot;,&quot;formatting&quot;, &quot;bold&quot;, &quot;italic&quot;, &quot;unorderedlist&quot;, &quot;orderedlist&quot;, &quot;link&quot;, &quot;image&quot;, &quot;video&quot;,&quot;variable&quot;],
  &quot;plugins&quot;: [&quot;fullscreen&quot;, &quot;video&quot;,&quot;variable&quot;],
  &quot;linkNewTab&quot;: true,
  &quot;toolbarFixed&quot;: true,
  &quot;variables&quot;:[&quot;Brand&quot;,&quot;Product&quot;]
}
</code></pre>
<p>Just click the <code>{x}</code> button in redactor to select the variable you want. These are more or less placeholders for where you want the replaced content to appear, hence variables.</p>
<p>This gets you something like:</p>
<p><a href="https://i.sstatic.net/56wk9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/56wk9.png" alt="Redactor Variables" /></a></p>
<p>The Redactor field outputs variables like:</p>
<p><code>&lt;span data-redactor-type=&quot;variable&quot;&gt;Brand&lt;/span&gt;</code></p>
<p>so you just need to do a quick find/replace in Twig on the content:</p>
<pre><code>{{ entry.body|replace({'&lt;span data-redactor-type=&quot;variable&quot;&gt;Brand&lt;/span&gt;':entry.brand.one.title,'&lt;span data-redactor-type=&quot;variable&quot;&gt;Product&lt;/span&gt;':entry.product.one.title}) }}
</code></pre>
<p>I used an Entries field as the example but you can use whatever field type you prefer.</p>
<p>The last thing to note is you'll need to either turn off HTML Purifer or add some code in a module/plugin to allow redactor's <code>data-redactor-type</code> data attribute on a span element or it will be cleansed off the next time you save.</p>
<p>The Redactor plugin actually <a href="https://github.com/craftcms/redactor/blob/v2/src/Field.php#L60" rel="nofollow noreferrer">comes with the exact code you need</a> to enable the Variables plugin to work, it's just not enabled.</p>
<pre><code>      use craft\redactor\events\ModifyPurifierConfigEvent;
      use craft\redactor\Field;
      use HTMLPurifier_AttrDef_Text;
      use yii\base\Event;
     
      Event::on(Field::class, Field::EVENT_MODIFY_PURIFIER_CONFIG, function(ModifyPurifierConfigEvent $e) {
           // Allow the use of the Redactor Variables plugin
           $e-&gt;config-&gt;getHTMLDefinition(true)-&gt;addAttribute('span', 'data-redactor-type', new HTMLPurifier_AttrDef_Text());
      });
</code></pre>

CC BY-SA 4.0
2021-07-19T16:16:46.850Z
2021-07-19T16:22:48.367Z
2021-07-19T16:22:48.367Z
RitterKnight
<p>i have some data in my entry like productnames &quot;Nike&quot;, &quot;Puma&quot; etc. which are headings i diplay in my template.</p>
<h2>{{ productnames1 }}</h2>
 "some text the contenteditor maybe wants do add"
<h2>{{ productnames2 }}</h2>
 "some text the contenteditor maybe wants do add"
<p>How can i create fields like textfields which contains data from the productnames that the contenteditor knows which text of which productname he is editing.</p>
<p>my best approach is to let the contenteditor count the number of productnames and corresponding to the number create new textfields which will be outputed through a loop matching the number of products.</p>
<p>explanation is a little wild. hope you can get my point.</p>

<entry><field>
Display entry data dynamicly in textfield
# Display entry data dynamicly in textfield

(Asked by: username_0 on 2021-07-18)

i have some data in my entry like productnames "Nike", "Puma" etc. which are headings i diplay in my template.

## {{ productnames1 }}

"some text the contenteditor maybe wants do add"

## {{ productnames2 }}

"some text the contenteditor maybe wants do add"

How can i create fields like textfields which contains data from the productnames that the contenteditor knows which text of which productname he is editing.

my best approach is to let the contenteditor count the number of productnames and corresponding to the number create new textfields which will be outputed through a loop matching the number of products.

explanation is a little wild. hope you can get my point.

**Tags:** entry, field

---

## 2 answers

### Answer by username_1 on 2021-07-18. Score: 1

Instead of splitting the content up into multiple fields, you can put your editors in charge of outputting the product headlines by using reference tags. So your field content could look like this:
{entry:nike:title}

some text the contenteditor maybe wants do add

{entry:puma:title}

some text the contenteditor maybe wants do add

In this example, nike and puma would be the entries' slugs. There are other ways to refer to specific entries, check the examples in the documentation linked below.
If I remember correctly, Craft should parse those automatically on output, otherwise you can use the parseRefs filter in your template.
Another maybe slightly more solid approach would be to use Matrix fields. You can define two block types for product references and custom text respectively. Then loop through them and for every product reference block, output the headline of the selected product as a headline. This would allow your editors more control over the content structure, and you more control over the resulting HTML.


---

### Answer by username_2 on 2021-07-19. Score: 0

The Variables plugin in the Redactor plugin might be useful in this case.
One way to handle it would be to create your variables, like Brand and Product.
Setup a Redactor field and add variable to buttons and plugins to the json config. Then inside variables define the variables you want, in this case Brand and Product, for example.
{
  "buttons": ["html","formatting", "bold", "italic", "unorderedlist", "orderedlist", "link", "image", "video","variable"],
  "plugins": ["fullscreen", "video","variable"],
  "linkNewTab": true,
  "toolbarFixed": true,
  "variables":["Brand","Product"]
}

Just click the {x} button in redactor to select the variable you want. These are more or less placeholders for where you want the replaced content to appear, hence variables.
This gets you something like:

The Redactor field outputs variables like:
Brand
so you just need to do a quick find/replace in Twig on the content:
{{ entry.body|replace({'Brand':entry.brand.one.title,'Product':entry.product.one.title}) }}

I used an Entries field as the example but you can use whatever field type you prefer.
The last thing to note is you'll need to either turn off HTML Purifer or add some code in a module/plugin to allow redactor's data-redactor-type data attribute on a span element or it will be cleansed off the next time you save.
The Redactor plugin actually comes with the exact code you need to enable the Variables plugin to work, it's just not enabled.
      use craft\redactor\events\ModifyPurifierConfigEvent;
      use craft\redactor\Field;
      use HTMLPurifier_AttrDef_Text;
      use yii\base\Event;
     
      Event::on(Field::class, Field::EVENT_MODIFY_PURIFIER_CONFIG, function(ModifyPurifierConfigEvent $e) {
           // Allow the use of the Redactor Variables plugin
           $e->config->getHTMLDefinition(true)->addAttribute('span', 'data-redactor-type', new HTMLPurifier_AttrDef_Text());
      });


---

