API usage

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

API usage

Petar Tahchiev
Hello,

I have this snippet: "< h3 th:text='#{a}'>< /h3>". What is the API I should use to produce this result:"< h3>b< /h3>" (please ignore the white space - the forum does not display my message)?

With Velocity I can do this:
        final StringWriter writer = new StringWriter();
        try {

            VelocityContext context = new VelocityContext();
            if (params != null) {
                for (Map.Entry<String, Object> e : params.entrySet()) {
                    context.put(e.getKey(), e.getValue());
                }
            }

            velocityEngine.evaluate(context, writer, "logUrl", content);
            return writer.toString();

Is there something similar in Thymeleaf?
Reply | Threaded
Open this post in threaded view
|

Re: API usage

Zemi
Administrator
Hello,

if your are using #{...} syntax you have to specify a key in and internationalization file, i.e., something like

a=b

Please take a look at the introduction article at
  http://www.thymeleaf.org/doc/articles/standarddialect5minutes.html

Regards,
  Zemi

Reply | Threaded
Open this post in threaded view
|

Re: API usage

Petar Tahchiev
Hello Zemi,

I read the introduction article. However it doesn't mention how to use the API of Thymeleaf. I can use it if I have a template file, and yes - it works fine. However I'm struggling when I have a piece of string that I want to parse. Please have a look at my example with Velocity.
Reply | Threaded
Open this post in threaded view
|

Re: API usage

Zemi
Administrator
So you want to use Thymeleaf standalone, not using templates.

Ok, we do something similar in the itutorial app, please take a look at
   https://github.com/thymeleaf/thymeleaf-itutorial/blob/2.1-master/src/main/java/org/thymeleaf/tools/memoryexecutor/StaticTemplateExecutor.java

which is used at
  https://github.com/thymeleaf/thymeleaf-itutorial/blob/2.1-master/src/main/java/org/thymeleaf/itutorial/TemplateExecutor.java

Regards,
  Zemi