Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to use quotes in expressions #9

@jobinbasani

Description

@jobinbasani

I'm trying to do a String comparison operation and show/hide text in a template. The code is as below:

<% if(P_KEY == "ARF") { %>

Display ARF Text

<% } else { %>

Display non-ARF text

<% } %>

This throws an exception as below:

groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: 
GStringTemplateScript16.groovy: 2: Invalid variable name. Must start with a letter but was: ?ARF? 
. At [2:395]  @ line 2, column 395. 
   cd6c79a8e03"""; if(P_KEY == ?ARF?) { 
                                 ^ 

1 error 

        at groovy.text.GStringTemplateEngine$GStringTemplate.<init>(GStringTemplateEngine.java:190) 
        at groovy.text.GStringTemplateEngine.createTemplate(GStringTemplateEngine.java:105) 
        at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:38) 
        at org.scriptlet4docx.docx.DocxTemplater.processCleanedTemplate(DocxTemplater.java:158) 
        at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:255) 
        at org.scriptlet4docx.docx.DocxTemplater.processAndReturnInputStream(DocxTemplater.java:213) 
        at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:230) 

I tried to use def key="ARF" and then use the variable to compare, but that also didnt work.
I'm using v0.7.6
Can you please take a look?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions