Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone template population #285

Closed
farannegarestan opened this issue Feb 23, 2015 · 11 comments
Closed

Standalone template population #285

farannegarestan opened this issue Feb 23, 2015 · 11 comments

Comments

@farannegarestan
Copy link

I wish there was a feature to populate a template and give out a string to send as an email. I had to resort to Velocity for that purpose while all my front end is using jtwig. Do you have anything under development for that or I can work on it.

@joao-de-melo
Copy link
Member

Hi @farannegarestan,

I've used Jtwig for that purpose before. Check this related example:

https://github.com/jtwig/jtwig-examples/blob/master/simple-app/src/main/java/com/lyncode/jtwig/example/Sample.java

@farannegarestan
Copy link
Author

That's awesome! Thanks!

On Mon, Feb 23, 2015 at 11:51 AM, João Melo notifications@github.com
wrote:

Hi @farannegarestan https://github.com/farannegarestan,

I've used Jtwig for that purpose before. Check this related example:

https://github.com/jtwig/jtwig-examples/blob/master/simple-app/src/main/java/com/lyncode/jtwig/example/Sample.java


Reply to this email directly or view it on GitHub
#285 (comment).

@realcnbs
Copy link

That example won't compile in latest versions.

Map<String, String> resources = new HashMap<>();

// ... populate resources map with templates and their names
// ... below you choose one of them to render in this case "tmpl.html.twig"
MapJtwigResource resource = new MapJtwigResource("tmpl.html.twig", resources);
JtwigTemplate tmpl = new JtwigTemplate(resource, new JtwigConfiguration());

JtwigModelMap modelMap = new JtwigModelMap();
modelMap.put("someVar", "someVarValue");

String out = tmpl.output(modelMap);

And also with JtwigConfiguration you may do things like these:

configuration.render().functionRepository()
            .include(new DateFunctions())
            .include(new ImageTwigFunctions())
            .include(themeJtwigFunctions)
    ;
configuration.render().strictMode(false).logNonStrictMode(true);

@joao-de-melo
Copy link
Member

@realcnbs Is MapJtwigResource part of 3.1.1?

@EvSpirit
Copy link

It seems the example mentioned above won't work cause there is no JtwigContext in 3.1.1. Do you have any up-to-date example?

@realcnbs
Copy link

@lyncodev Not sure, i am on snapshot always :)

@realcnbs
Copy link

@EvSpirit check my comment for working version.

@EvSpirit
Copy link

@realcnbs , thanks a lot! But I'm on 3.1.1 and there is no MapJtwigResource as @lyncodev said before. I'm migration from 2.1.x (huh!) so I have to look into some sources :)

@realcnbs
Copy link

@EvSpirit well, you could just copy paste it to your project and use, in case you need an in memory resource

@joao-de-melo
Copy link
Member

@thomas-p-wilson
Copy link

Is this still open for discussion? Or should the ticket be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants