casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
737 stars 54 forks source link

How to use 2 html template and plain text template in same project? #317

Closed hurelhuyag closed 4 months ago

hurelhuyag commented 6 months ago

I tried to use 2 use 2 execution setup in maven pom.xml. But the output is empty.

            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>${jte.version}</version>
                <executions>
                  <execution>
                    <id>generate-jte-html</id>
                    <phase>generate-sources</phase>
                    <goals>
                      <goal>generate</goal>
                    </goals>
                    <configuration>
                      <sourceDirectory>${basedir}/src/main/jte/</sourceDirectory>
                      <targetDirectory>${project.build.directory}/jte-classes</targetDirectory>
                      <contentType>Html</contentType>
                    </configuration>
                  </execution>
                  <execution>
                    <id>generate-jte-plain</id>
                    <phase>generate-sources</phase>
                    <goals>
                      <goal>generate</goal>
                    </goals>
                    <configuration>
                      <sourceDirectory>${basedir}/src/main/jte-plain/</sourceDirectory>
                      <targetDirectory>${project.build.directory}/jte-classes</targetDirectory>
                      <contentType>Plain</contentType>
                    </configuration>
                  </execution>
                </executions>
            </plugin>

Used example code:

public class GenerateWWW {

    private final TemplateEngine templateEngine = TemplateEngine.createPrecompiled(ContentType.Plain);

    public GenerateWWW() throws IOException {
        var path = Path.of("/home/hurlee/Desktop/domain.com.nginx");
        var output = new FileOutput(path, StandardCharsets.UTF_8);
        templateEngine.render(
            "nginx_with_www.jte",
            Map.of("domain", "domain.com", "withSsl", false),
            output
        );
    }

    public static void main(String[] args) throws IOException {
        new GenerateWWW();
    }
}
kelunik commented 6 months ago

I think you'll need to provide two different target directories.