Question: I am getting a string which already has a thymeleaf tags as below:

```
String html = "<span th:text="${fisrtText}"></span> Indicative Terms for a <span th:text="${currency}"></span><span th:text="${amount}"></span>M <span th:text="${type}"></span> Facility"; 

```

I am setting the above string to context variable as:

```
context.setVariable("topSection", html);

```

I am setting the context variable with values to be used to replace tags in above string:

```
org.thymeleaf.context.Context context = new org.thymeleaf.context.Context();    
context.setVariable("fisrtText", "This is fisrt Text");
context.setVariable("currency", "$");
context.setVariable("amount", 256.10);
context.setVariable("type", "Loan");

```

Now in template.html I am trying to get it as below:

```
<span th:utext="@{__${topSection}__}"></span>

```

I am expecting to get the html string to be replaced with values available in context. But its returning the same html as it is without any processing:

```
<span th:text="${fisrtText}"></span> Indicative Terms for a <span th:text="${currency}"></span><span th:text="${amount}"></span>M <span th:text="${type}"></span> Facility"

```

Any help will be appreciated.

Answer: 
Better to use multiple template Engine bean one for String and other one for resource HTML files.

1) For resource File

```
    @Bean(name ="templateEngine")       
    public SpringTemplateEngine getTemplateEngine() {
      SpringTemplateEngine templateEngine = new SpringTemplateEngine();

      templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver(););
      templateEngine.setMessageSource(messageSource);
      templateEngine.setTemplateEngineMessageSource(messageSource);
      return templateEngine;
   }

```

You can set prefix and suffix for ClassLoaderTemplateResolver.

2) String Template resolver : 

```
@Bean(name ="stringTemplateEngine")     
    public SpringTemplateEngine getTemplateEngine() {
      SpringTemplateEngine templateEngine = new SpringTemplateEngine();

      templateEngine.setTemplateResolver(new StringTemplateResolver(););
      return templateEngine;
   }

```

Now first parse string variable with thymeleaf tag using stringTemplateEngine.

```
String html = "<span th:text="${fisrtText}"></span>";
String parsedHtml = stringTemplateEngine.process(html,context);

```

Now put ParsedHtml in context.

```
context.setVariable("topSection", parsedHtml);

```

then As @holmis83 suggested directly access you variable in template

```
<span th:utext="${topSection}"></span>

```
`@{...}` is a *link URL expression*. I think you want to use a *variable expression* `${...}`.

Your code adjusted:

```xml
<span th:utext="${__${topSection}__}"></span>

```

Note that `${topSection}` must evaluate to an expression, it can't be arbitrary Thymeleaf markup (with `th:text` for example).