Java modern template engine

Comments
  • EnvironmentConfiguration and charset problem

    EnvironmentConfiguration and charset problem

    Hi,

    I initialized Jtwig using Your example (https://github.com/jtwig/jtwig-examples/blob/master/gradle-jtwig-spring-simple/src/main/java/org/jtwig/example/config/WebConfig.java)

    @Bean
        public ViewResolver viewResolver () {
            JtwigViewResolver viewResolver = new JtwigViewResolver();
            viewResolver.setRenderer(JtwigRenderer.defaultRenderer());
            viewResolver.setPrefix("classpath:/templates/");
            viewResolver.setSuffix(".html.twig");
            return viewResolver;
        }
    

    I wanted to disable strict mode so I was trying to use EnvironmentConfiguration like this:

      @Bean
        public ViewResolver viewResolver() {
    
            EnvironmentConfiguration environmentConfiguration = EnvironmentConfigurationBuilder
                    .configuration()
                        .render()
                            .withStrictMode(false)
                            .withOutputCharset(Charset.forName("UTF-8"))
                    .and()
                        .parser()
                            .withoutTemplateCache()
                    .and()
                    .build();
    
            JtwigRenderer jtwigRenderer = new JtwigRenderer(environmentConfiguration);
    
            JtwigViewResolver viewResolver = new JtwigViewResolver();
            viewResolver.setRenderer(jtwigRenderer);
    
            viewResolver.setPrefix("classpath:/templates/");
            viewResolver.setSuffix(".html.twig");
    
            return viewResolver;
        }
    
    

    but page in browser does not display my locale spacial chars. I am given:

    użytkownik instead of użytkownik

    But if I initialize viewResolver like this:

     @Bean
        public ViewResolver viewResolver() {
    
            JtwigViewResolver viewResolver = new JtwigViewResolver();
    
            viewResolver.setRenderer(JtwigRenderer.defaultRenderer());
            viewResolver.setPrefix("classpath:/templates/");
            viewResolver.setSuffix(".html.twig");
            viewResolver.setContentType("text/html; charset=UTF-8");
    
            return viewResolver;
        }
    
    

    locales on my page are correct.

    Can You tell me if I incorrectly used EnvironmentConfiguration to change default configuration? Or there is simpler way to toggle strictMode ?

    Thx for help ;-)

    Maciej.

    Question Documentation 
    opened by replay111 25
  • Null variables should fail silently

    Null variables should fail silently

    If we're looking at reproducing the behaviour of Sensio's Twig, then null or non-existent variables should not produce an exception that interferes with the rendering of the template. I notice that #76 suggests the opposite, however. Where do we stand on this?

    If we're really looking to let developers know that a referenced variable is null or nonexistent, logging the issue rather than failing to render might make more sense.

    Investigate 
    opened by thomas-p-wilson 24
  • parent() Not implemented?

    parent() Not implemented?

    Hello. According to the docs i can use parent() inside an overriding block in order to render the extended block. I am getting this error :

    Caused by: com.lyncode.jtwig.exception.ParseException: Wrong function syntax
    Explanation: Input position (line 8, pos 11):
    {{ parent() }}
              ^
    
    opened by realcnbs 24
  • Twig's Character comparison different from PHP and JavaScript

    Twig's Character comparison different from PHP and JavaScript

    In the PHP and JS implementation of Twig the following (pseudo) code will output Man:

    $gender = "m";
    $template = "{% if gender == 'm' %} Man {% endif %}";
    

    In jTwig the same (pseudo) code will not output anything, since the single quotes in the template will indicate a Character and the double quotes indicate a String. Thus, the comparison will fail. Since we are using three implementations of Twig (PHP, JS and Java) this is a problem. PHP and JS do not differentiate between the types Character and String and jTwig should not do either for compability sake. I propose to cast Characters to Strings before each comparison function.

    Investigate Twig compatability 
    opened by steffenschebesta 15
  • UTF-8 content encoding issue

    UTF-8 content encoding issue

    Hi, Could this be a JTwig bug or (most likely) misconfiguration of Tomcat / Spring / JTwig? http://stackoverflow.com/questions/26593934/utf-8-encoding-issue-in-spring-webapp-with-jtwig-templates

    Bug (major) Code Review Twig compatability 
    opened by michlis 14
  • Refactor template model

    Refactor template model

    Some highlights:

    • RenderConfiguration, CompileConfiguration, and ParseConfiguration have been combined into the Environment
    • The various Resource implementations (StringJtwigResource, et al) have been refactored into a set of Loaders and Resources. The Environment is now solely responsible for managing the resolution and loading of resource. Multiple loaders may be specified through the use of the ChainLoader. As a result, the resolution process should always return a path relative to an arbitrary resource root, in much the same way as we specify a resource as 'client/list.twig' and whatnot.
    • Concurrent rendering demonstrated a hang when the output stream wasn't specified. This is resolved with an exception noting the problem. Helpful in unit tests
    • Unit tests have been widely refactored for uniformity, in addition to the refactoring required due to all my other changes.
    • Template caching is now supported. At minimum a per-execution cache is required due to the new resolution and loading process, but the cache can be cleared after execution. In my local tests, render time drops considerably on the second run. I've seen a drop in one of my projects from ~1200ms to ~25ms after a second run. TODO: Auto-clear the ExecutionCache after rendering has completed.
    • With the existence of the Template and its implementations, we now have a place to store per-template information, present examples being Macro and Block information, for later usage. This also allows us to use the SetVariable tag during template extension.
    Code Review 
    opened by thomas-p-wilson 13
  • Spring 4.0.6 + Hibernate 4.3.6 + jTwig 2.1.7

    Spring 4.0.6 + Hibernate 4.3.6 + jTwig 2.1.7

    Hi,

    does Your jTwig work with Spring 4.0.6 + Hibernate 4.3.6 properly? I have a strange problem with extendings templates...

    ie:

    @Controller
    public class DBTestController {
    
        @Autowired
        private SysUserDAO sysUserDao;
    
        @RequestMapping(value = "dbtest.htm")
        public String reqDBTest(ModelMap model) {
    
            List<SysUser> listUsers = sysUserDao.list();
    
            model.addAttribute("users", listUsers);
    
            return "dbtest";
        }
    }
    

    dbtest.twig:

    {% extends "master.twig" %} 
    
    {% block module_content %}
    
    <ul class="list-group">
        {% for user in users %}
    
        <li class="list-group-item">{{ user.st_nazwisko }} {{ user.st_imie }} <span
            class="badge">{{ user.pm }}</span>
        </li> {% endfor %}
    </ul>
    
    {% endblock %}
    

    master.twig has some block definitions and css/js includes.

    After deploy and entering url to /dbtest.htm I am given such errors:

    Context Path:
    /k100
    
    Servlet Path:
    /dbtest.htm
    
    Path Info:
    null
    
    Query String:
    null
    
    Stack Trace
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
    io.undertow.servlet.handlers.ServletHan.....
    

    but some templates extends master without any problem. If in this (dbtest.twig) template I erase first line: {% extends "master.twig" %} everything works but I have no css/jss and my graphic templates enabled......

    Can U give some advice how to solve this?

    opened by replay111 13
  • String concate not supported?

    String concate not supported?

    It seems that jtwig doesn't support string concate (at least using ~).

    For every try I get syntax error.

    {% set fb = 'foo' ~ 'bar' %}

    Wrong set syntax

    {{ 'foo' ~ 'bar' }}

    Wrong output syntax

    Am I doing something wrong?

    opened by fritzfs 11
  • String Comparison with an Null Object on one Site

    String Comparison with an Null Object on one Site

    The RelationalOperations::eq method has a null check implemented, but this will fail for string comparisons like this:

    {% if recipient.attr != "" %}{{ recipient.attr }}{% else %}no or empty attribute{% endif %}
    

    If recipient.attr is null, e.g. not set, this condition does not output the else branch. This is due to a missing String check for the other argument.

    I will create a fix+test and a pull request.

    What about comparisons of Date objects?

    opened by stefanmeissner 11
  • Standalone template population

    Standalone template population

    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.

    opened by farannegarestan 11
  • Render template in method

    Render template in method

    Hi,

    I want to return html as response in my json structure (one of the field), and I wanted to render this html in method using Your JTwig engine. Is it possible to do this?

    Question 
    opened by replay111 8
  • filter() in for statement does not working

    filter() in for statement does not working

    An error will occur if try to narrow the condition with filter in the for statement.

    {% set sizes = [34, 36, 38, 40, 42] %}
    {% for v in sizes|filter(v => v > 38) -%}
        {{ v }}
    {% endfor %}
    

    Outputs

     org.jtwig.parser.ParseException: classpath:/templates/index.twig (Line: 8, Column: 19) -> Malformed for loop start syntax, missing code island ending symbol
    {% for v in sizes|filter(v => v > 38) -%}
    

    It should output as follows:

    40
    42
    

    https://twigfiddle.com/ljwm49

    opened by logue 0
  • Is Jtwig dead?

    Is Jtwig dead?

    Hello

    I love Jtwig and it is my go-to templating engine every time I need one. I've noticed that the development is somewhat stagnated and no new features are added. Does it mean that Jtwig is dead? I sure hope not..

    opened by eXsio 6
  • Jtwig-web ships a guava version with known vulnabilities

    Jtwig-web ships a guava version with known vulnabilities

    jtwig web has a dependency to guava version 18 that has a known vulnability: https://nvd.nist.gov/vuln/detail/CVE-2018-10237

    I'm not sure if this is really an issue with jtwig, but it triggers alerts with security scanners like Snyk or the OWASP-Dependency-Check. This might also cause projects to run on older versions of guava, depending on the order of dependencies in the build file and expose them to this issue. So I suppose we update to the latest guava version, or at least 24.1.1 where this issue was fixed.

    opened by gtudan 0
  • Defined function error with strict mode and specific argument type

    Defined function error with strict mode and specific argument type

    When running in strict mode the defined function will throw an exception (instead of returning false) when it is passed a parameter which doesn't exist but has a parent object that does.

    For example the following template snippet will throw an exception if foo is defined but foo.bar is not;

    {% if( defined(foo.bar) ) %}
    ...
    {% endif %}
    

    I'm not sure if this is the best way to do it, but I think it can be fixed by changing SelectionOperationCalculator:ln33 so that it throws a ResolveValueException instead of a CalculationException, which will be caught an handled inside DefinedFunction.

    https://github.com/jtwig/jtwig-core/blob/4ec125756e2883ce51114747b9beef93b8a1b15b/src/main/java/org/jtwig/render/expression/calculator/operation/binary/calculators/selection/SelectionOperationCalculator.java#L33

    opened by GeraintJones-STW 0
  • Evaluate function

    Evaluate function

    Hello,

    I'm trying to implement evaluate function example here but without success. When I create the extension/function I cannot access the model to pass it again.

    Has anyone already done something similar?

    @lyncodev do you plan to implement this in the future?

    opened by vencivenc 0
Releases(5.87.0.RELEASE)
Owner
Jtwig
Modern Java Template Engine
Jtwig
Java 8 optimized, memory efficient, speedy template engine producing statically typed, plain java objects

Rocker Templates by Fizzed Fizzed, Inc. (Follow on Twitter: @fizzed_inc) Sponsored by Rocker is proudly sponsored by Greenback. We love the service an

Fizzed, Inc. 669 Dec 29, 2022
jte is a secure and lightweight template engine for Java.

jte is a secure and lightweight template engine for Java. All jte templates are compiled to Java class files, meaning jte adds essentially zero overhe

Andreas Hager 457 Dec 22, 2022
ST (StringTemplate) is a java template engine (with ports for C#, Python, and Objective-C coming) for generating source code

ST (StringTemplate) is a java template engine (with ports for C#, Python, and Objective-C coming) for generating source code, web pages, emails, or an

Antlr Project 851 Jan 5, 2023
Multiproject template for ForgeGradle development environments

ForgeGradle Multiproject Template This repository provides a template for multiproject development environments using ForgeGradle. Project structure T

Néstor Amador 10 Jun 3, 2022
A little template project to

FX Modules This is a little project that can be used as a template for modularized JavaFX projects. The main branch is based on JDK17, other version c

Gerrit Grunwald 27 Dec 12, 2022
Pebble is a java templating engine inspired by Twig

Pebble Pebble is a java templating engine inspired by Twig. It separates itself from the crowd with its inheritance feature and its easy-to-read synta

null 985 Dec 23, 2022
a pug implementation written in Java (formerly known as jade)

Attention: jade4j is now pug4j In alignment with the javascript template engine we renamed jade4j to pug4j. You will find it under https://github.com/

neuland - Büro für Informatik 700 Oct 16, 2022
Java modern template engine

Jtwig Project Documentation Project Status Coverage Version jtwig-reflection jtwig-core jtwig-web jtwig-pluralization jtwig-spring jtwig-translate-ext

Jtwig 298 May 19, 2022
Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.

An open source rule engine, DMN engine and complex event processing (CEP) engine for Java™ and the JVM Platform. Drools is a business rule management

KIE (Drools, OptaPlanner and jBPM) 4.9k Dec 31, 2022
Java 8 optimized, memory efficient, speedy template engine producing statically typed, plain java objects

Rocker Templates by Fizzed Fizzed, Inc. (Follow on Twitter: @fizzed_inc) Sponsored by Rocker is proudly sponsored by Greenback. We love the service an

Fizzed, Inc. 669 Dec 29, 2022
A modern engine for modded Minecraft.

Flywheel A modern engine for modded Minecraft. About The goal of this project is to provide tools for mod developers so they no longer have to worry a

null 136 Dec 30, 2022
jte is a secure and lightweight template engine for Java.

jte is a secure and lightweight template engine for Java. All jte templates are compiled to Java class files, meaning jte adds essentially zero overhe

Andreas Hager 457 Dec 22, 2022
A Java-based template project for the FastJ Game Engine.

FastJ Java Template Program Requirements Java 16 JDK Basic understanding of Java Initial Setup Download the Template You have a few options for gettin

Andrew Dey 13 May 15, 2022
ST (StringTemplate) is a java template engine (with ports for C#, Python, and Objective-C coming) for generating source code

ST (StringTemplate) is a java template engine (with ports for C#, Python, and Objective-C coming) for generating source code, web pages, emails, or an

Antlr Project 851 Jan 5, 2023
A query language for JSON and a template engine to generate text output.

Josson & Jossons Josson is a query language for JSON. Jossons is a template engine to generate text output. Features and Capabilities of Josson Query

Octomix Software 16 Dec 14, 2022
Vaadin 6, 7, 8 is a Java framework for modern Java web applications.

Vaadin Framework Vaadin allows you to build modern web apps efficiently in plain Java, without touching low level web technologies. This repository co

Vaadin 1.7k Jan 5, 2023
Modern Java - A Guide to Java 8

Modern Java - A Guide to Java 8 This article was originally posted on my blog. You should also read my Java 11 Tutorial (including new language and AP

Benjamin Winterberg 16.1k Jan 5, 2023
Modern Java - A Guide to Java 8

Modern Java - A Guide to Java 8 This article was originally posted on my blog. You should also read my Java 11 Tutorial (including new language and AP

Benjamin Winterberg 16.1k Dec 29, 2022