Open SMoONF61 opened 3 years ago
+1 for having the ability to be able to do conditionals. Would be quite useful when dealing with incomplete datasets (common in openstreetmap).
+1
It's a non-trivial feature, especially because it involves security. Some options to consider:
There is also a potential performance issue to consider if the template is complex and the displayed data is huge.
I wanted to work on this feature (but I don't know the umap codebase). I think the "full JS syntax" solutions looks good and can be made somewhat secure (by shadowing all global variables, so practically giving access only to the variables of interest).
One general question is how to remain backward compatible? Should the new syntax be used only if the popup template starts with some key word (like actually this will become a new popup classjs:
)...
I'm reporting on some explorations. I implemented a prototype for the "full JS (expression) syntax" and I think it is relatively secure, however:
many tags contain :
so to have contact: ${contact:email}
work (while it is not a valid js expression), it needs some string replacement of any "letter : letter" for it to work seamlessly. This seems ok for most use cases, it just conflicts with any templates that would contain some "letter : letter", like one that explicitly write tag names contact:email ${contact:email}
(this can also be worked around by some reverse string replacement)
the question of whether js is adequate for easy conditionals etc remains...
${'contact:email' in _ ? 'contact: ' + contact:email : ''}
Hi,
I think that it would be an interesting feature.
For instance, I've schools map and I want to indicate if it exists particularities that doesn't exist in all the schools (an optional teaching or special class). The code I use to display the information in a single line is:
Particularities: {particularitie1}, {particularitie2}, {particularitie3}
Now, if the fields "particularitie1", "particularitie2", "particularitie3" are empty, I've the title "Particularities:" but nothing after. And the displaying is:
Particularities: , ,
So hiding this title would improve the displaying.
The problem is the same with a single field but there's a workaround if the field value contains "none" instead of no value : the line is displayed even there's nothing interesting to show.
Regards,
Thierry
I wonder if we can start with the simple null case and don't allow actual input: {if name} {name} {endif}
We already have minimal null-detection logic with "or" pipes as in {name|description|"none"}
so simply detecting emptiness shouldn't be much more work or security issue
It would be interesting, in the popup template, to be able to put as a condition that the field is not null. Something like this :
Unless this is already possible? (Please let me know if this is the case! 😉 )