# Replace placeholders in HippoHtml

**URL:** <https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [February 16, 2022, 1:57pm UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013 "2022-02-16T13:57:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://community.bloomreach.com/u/Dani)\
**Post date:** [February 16, 2022, 1:57pm UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/1 "2022-02-16T13:57:56Z")

</div>

Hi all,

I’m trying to replace placeholders set by content editors in String and Hippohtml fields. For the string fields I found a way to filter out the placeholders and replace them. Now I’m trying the same for the HippoHtml, but the problem I’m facing is that when I use hippohtml.getContent some of the hippohtml information is lost. So I would be able to replace it but I’m missing other information. Anyone an idea about how to solve this?

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [February 22, 2022, 10:47am UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/2 "2022-02-22T10:47:51Z")

</div>

If you are using freemarker you can use the messageReplace tag. See [1].

[1][HST Tag Library for Substituting Variables in Content - Bloomreach Experience Manager - The Fast and Flexible Headless CMS](https://documentation.bloomreach.com/14/library/concepts/translations/hst-2-tag-library-for-substituting-variables-in-content.html)

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://community.bloomreach.com/u/Dani)\
**Post date:** [February 22, 2022, 12:43pm UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/3 "2022-02-22T12:43:23Z")

</div>

We don’t use freemarker. We use Bloomreach headless so with a react frontend.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [February 22, 2022, 1:12pm UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/4 "2022-02-22T13:12:05Z")

</div>

That’s slightly more work then, as I don’t think there is any equivalent of the messageReplace tag in the spa sdk. Since you already have the a way to replace the placeholders in strings it seems most of the work is already done.

When you render html you do something like this:

```auto
   {content && <div dangerouslySetInnerHTML={{ __html: page.rewriteLinks(page.sanitize(content.value)) }} />}

```

The output of this is what you would need to manipulate.

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://community.bloomreach.com/u/Dani)\
**Post date:** [February 23, 2022, 9:12am UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/5 "2022-02-23T09:12:30Z")

</div>

And what if we want to solve it in the backend. For a string field I made this solution.

```auto
@HippoEssentialsGenerated(internalName = "univecommon:title")
    public String getTitle() {
        ReplacePlaceholdersUtilImpl replacePlaceholdersUtil = new ReplacePlaceholdersUtilImpl();
        String title = getSingleProperty("univecommon:title");
        List<String> placeholders = replacePlaceholdersUtil.findPlaceholder(title);
        if (placeholders.isEmpty()) {
            return title;
        }
        HttpServletRequest servletRequest = RequestContextProvider.get().getServletRequest();
        for (String placeholder : placeholders) {
            String valueResourceBundle = replacePlaceholdersUtil.getValueResourceBundle(placeholder);

            if (valueResourceBundle.equals(StringUtils.EMPTY))
                break;

            String valueJson = replacePlaceholdersUtil.getValueJson(servletRequest, valueResourceBundle);
            title = title.replace(placeholder, valueJson);
        }
        return title;

```

and I would like to do this for a HippoHtml field.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [February 23, 2022, 12:29pm UTC](https://community.bloomreach.com/t/replace-placeholders-in-hippohtml/3013/6 "2022-02-23T12:29:34Z")

</div>

I think you will have to do what is done in the hst:html tag. The class that does the work here is “org.hippoecm.hst.tag.HstHtmlTag”.

What you want to do looks something like:

```auto
ContentRewriter<String> cr = ContentRewriterFactory factory = HstServices.getComponentManager().getComponent(ContentRewriterFactory.class.getName());

cr.setFullyQualifiedLinks(<boolean>);
cr.setImageVariant(<ImageVariant>);
cr.setCanonicalLinks(<Boolean>);
html = cr.rewrite(hippoHtml.getContent(), hippoHtml.getNode(), requestContext);

```

This code is not complete. You should look in the tag class I mentioned for a complete example.
