Java modern template engine
Overview
Comments
-
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 ofuż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 togglestrictMode
?Thx for help ;-)
Maciej.
Question Documentation -
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 -
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() }} ^
-
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
Investigate Twig compatabilityCharacter
and the double quotes indicate aString
. 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 typesCharacter
andString
and jTwig should not do either for compability sake. I propose to castCharacter
s toString
s before each comparison function. -
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 -
Refactor template model
Some highlights:
RenderConfiguration
,CompileConfiguration
, andParseConfiguration
have been combined into theEnvironment
- The various
Resource
implementations (StringJtwigResource
, et al) have been refactored into a set ofLoader
s andResource
s. TheEnvironment
is now solely responsible for managing the resolution and loading of resource. Multiple loaders may be specified through the use of theChainLoader
. 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 beingMacro
andBlock
information, for later usage. This also allows us to use the SetVariable tag during template extension.
-
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?
-
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?
-
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?
-
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.
-
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 -
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
-
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..
-
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.
-
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 butfoo.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 aResolveValueException
instead of aCalculationException
, which will be caught an handled insideDefinedFunction
.https://github.com/jtwig/jtwig-core/blob/4ec125756e2883ce51114747b9beef93b8a1b15b/src/main/java/org/jtwig/render/expression/calculator/operation/binary/calculators/selection/SelectionOperationCalculator.java#L33
-
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?
Releases(5.87.0.RELEASE)
-
5.87.0.RELEASE(Apr 14, 2018)
Fixing spring boot compatibility
Source code(tar.gz)
Source code(zip)
-
5.86.0.RELEASE(Jul 19, 2017)
- #335
- #321
- #343
- #60
- Ability to configure render listeners
- Other fixes
Source code(zip)
-
5.85.3.RELEASE(Feb 26, 2017)
- Fixing autoescape issue (#332)
- Fixing import _self issue (#333)
- Code refactor on render context to allow custom contexts
Source code(zip)
-
jtwig-4.0.0-beta-20150305223257(Mar 5, 2015)
Release of version 4.0.0-beta-20150305223257
Source code(tar.gz)
Source code(zip)
-
jtwig-4.0.0-beta-20150224002937(Feb 24, 2015)
Release of version 4.0.0-beta-20150224002937
Source code(tar.gz)
Source code(zip)
-
jtwig-4.0.0-beta-20150214180533(Feb 14, 2015)
Release of version 4.0.0-beta-20150214180533
Source code(tar.gz)
Source code(zip)
-
jtwig-4.0.0-beta-20150214124629(Feb 14, 2015)
Release of version 4.0.0-beta-20150214124629
Source code(tar.gz)
Source code(zip)
-
jtwig-4.0.0-beta-20150214120258(Feb 14, 2015)
Release of version 4.0.0-beta-20150214120258
Source code(tar.gz)
Source code(zip)
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
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
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
Multiproject template for ForgeGradle development environments
ForgeGradle Multiproject Template This repository provides a template for multiproject development environments using ForgeGradle. Project structure T
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
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
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/
Java modern template engine
Jtwig Project Documentation Project Status Coverage Version jtwig-reflection jtwig-core jtwig-web jtwig-pluralization jtwig-spring jtwig-translate-ext
Java CMS engine. Host and develop multiple websites inside a single instance through the GUI and benefit from features like A/B testing, affiliate tracking tools, and a high performance template engine with CSS stylesheets processing & scripts minification.
Free enterprise Java CMS https://ncms.softmotions.com ηCMS features Multiple websites on a single ηCMS application node. Can handle hundreds of simult
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
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
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
Manifold plugs into Java to supplement it with powerful features, from Type-safe Metaprogramming (direct access to GraphQL, JSON, XML, etc.), Extension Methods, Operator Overloading, and Unit Expressions to an integrated Template Engine and a Preprocessor. All fully supported in IntelliJ IDEA and Android Studio. Simply add Manifold to your project and begin taking advantage of it.
What is Manifold? Manifold plugs into Java to supplement it with powerful features, including: Type-safe Meta-programming Extension Methods Operator O
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
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
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
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
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
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
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