TemplaterExamples icon indicating copy to clipboard operation
TemplaterExamples copied to clipboard

Navigation expressions not working?

Open asmaier opened this issue 1 year ago • 4 comments

I have the following simple.json file:

{
  "colors": [
    {"name": "red"},
    {"name": "green"},
    {"name": "blue"}
  ]
}

and a simple_template.xlsx with expressions like

{{atColor = colors:at(1)}}
 
My favorite color is {{atColor.name}}.
 
[[colors.name]]
 
[[colors:at(0).name]]
 
[[colors:top(2).name]]

I run it like java -jar templater-json.jar simple_template.xlsx simple.json simple.xlsx But in the output simple.xlsx I can only see that [[colors.name]] gets replaced:

{{atColor = colors:at(1)}}
 
My favorite color is {{atColor.name}}.
 
red
green
blue
 
[[colors:at(0).name]]
 
[[colors:top(2).name]]

It seems like all the navigation expressions are ignored. Am I doing something wrong here? Or are navigation expressions not supported by templater-json.jar ?

simple_template.xlsx simple.json simple.xlsx

asmaier avatar May 24 '24 13:05 asmaier

As far as I see its not configured: https://github.com/ngs-doo/TemplaterExamples/blob/master/Intermediate/TemplaterJson/src/main/java/hr/ngs/templater/json/TemplaterJson.java#L78 So you can configure it and recompile your version

zapov avatar May 24 '24 14:05 zapov

Would it be much effort to add .navigateSeparator(':', null) to the configuration builder of the templater-json.java and then release a new version 8.0.1 for everyone? I think it is confusing that the documentation says

"There are two built-in navigation plugins. .. at(INDEX)...top(COUNT)",

but these are not activated by default. It took me quite some digging in the documentation to see that

"Navigation plugins are disabled by default, but can be enabled if metadata separator is defined"

and that this also must be done to activate the build-in navigation plugins. The Getting started section of the documentation also seems to imply that navigation expressions are enabled by default, so I might not be the only one to stumble over this when using the command line tool templater-json.java.

asmaier avatar May 24 '24 15:05 asmaier

Eh, it also says just before

To enable navigation expressions, first navigation metadata must be defined

While most of the examples are using : a lot of customers have their own versions such as / or | or similar. I think for now it would be easier for your to build your own version which behaves as you expect it to.

zapov avatar May 28 '24 04:05 zapov

Ok, I will do that. Nevertheless here is a pull request https://github.com/ngs-doo/TemplaterExamples/pull/73 to add navigation expressions in the templater-json jar. Maybe this is useful for anyone.

asmaier avatar May 28 '24 10:05 asmaier