Skip to content
Advertisement

Class name for Liquide / Liqp Project in Lucee / Coldfusion,

I’m trying to use the Liquid template engine in coldfusion and I’m not sure what “class name” to use when creating the java object in lucee

Relevant Documentation
Liqp Project: https://github.com/bkiers/Liqp
Lucee Doc:https://docs.lucee.org/reference/functions/createobject.html
Jar File: https://mvnrepository.com/artifact/nl.big-o/liqp

jLiq = createObject("java","Liquid", expandPath('/app/lib/liqp-0.7.9.jar'))

for the 2nd parameter, classname, I’ve tried many combinations(liqp,Liquid,liqp-0.7.9,liquid.parser,etc), but nothing seems to work, I’ve inspected the jar file for ideas. Anybody have any ideas on how to reference this java object in coldfuison?

Advertisement

Answer

The JAR on MVN Repository isn’t bundled with its dependencies, so you either put everything into a single fat JAR or specify a folder with all the single JAR files. Once you’ve done that, you need to create class objects by specifying package + classname:

<cfscript>

    LiquidTemplate = createObject("java", "liqp.Template", expandPath("liqp-0.7.9.jar"));

    template = LiquidTemplate.parse("hi {{name}}");
    rendered = template.render({ "name": "tobi" });

    writeOutput(rendered); // hi tobi

</cfscript>

As a side note: Why would you use a template engine when you are already on CFML?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement