Git Product home page Git Product logo

Comments (6)

casid avatar casid commented on August 16, 2024

Hey @M-Plu,

I'm not entirely sure what you want to try to achieve. Maybe you could provide a code example of what you want to do?

Cheers!

from jte.

M-Plu avatar M-Plu commented on August 16, 2024

Hey @casid

sure. Currently I have JTE files in the project resources. Then I use the following code to create a string output with these files.

CodeResolver codeResolver = new ResourceCodeResolver("de/svws_nrw/module/reporting");
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);
templateEngine.setTrimControlStructures(true);
StringOutput output = new StringOutput();
templateEngine.render("jte/schule.jte", reportingSchule, output);

So the CodeResolver needs a folder and the templateEngine.render method needs a file.

What I would like to do is passing a string (with content of a JTE file) to the templateEngine.render method, e. g.

var myString = """
@import ...
@param ..."""

CodeResolver codeResolver = new **String**CodeResolver();
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);
templateEngine.setTrimControlStructures(true);
StringOutput output = new StringOutput();
templateEngine.render(**myString**, reportingSchule, output);

I hope that makes sense to you. Thank you for your help.

from jte.

kelunik avatar kelunik commented on August 16, 2024

Could you share some details on your use case?

from jte.

M-Plu avatar M-Plu commented on August 16, 2024

Currently we test JTE as a replacement for thymeleaf.

We have created a server-side PDF-Reporting with thymeleaf and OpenHtmlToPDF.

  • From the html-template-files we create the html-files with data.
  • Then these files are converted to PDF using PrintCSS and OpenHtmlToPDF.

One plan is to store those html-templates in the DB of the project (instead of the resources of teh project). So it would be nice to pass the html-template from DB directly to the template-engine.

With thymeleaf this is possible, in JTE I did not find a way to do the same.

from jte.

casid avatar casid commented on August 16, 2024

@M-Plu you could implement the CodeResolver interface, so that templates are loaded from the database.

However, I wouldn't recommend jte for your usecase.

First, there probably won't be any IDE support for templates in the database, so maintaining the templates could become easily a pain, since jte without code completion is pretty hard to write. Think of Java without an IDE.

Second, you would need to run a JDK compiler in production. When a bad actor somehow is able to insert a jte template in your database, it will be compiled and you instantly have a remote code execution problem.

jte is really meant to be used in a way like regular code. Part of the repository and precompiled before running in production, like regular Java code.

Hope this helps with your decision!

from jte.

M-Plu avatar M-Plu commented on August 16, 2024

@casid Thank you for your feedback and opinion. We will keep it in mind.

from jte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.