Closed solsticesurfer closed 6 years ago
Since this is plugin responsibility, the question becomes can plugin access another field. And the answer is, it's not simple...
To do it in a simple scenario you need to have a reference to the parent of the object on which it's executing. That could work even currently if you use pattern such as:
[[rootPath]:onEmpty(FieldA,FieldB)]
which is kind of a version of the same thing (with the exception that it requires a path.
But the alternative is that before processing, you put that object into some shared reference, eg: thread static, and then you can access it from your plugin. You can use that kind of way to solve this issue even with your example.
But it becomes trickier if fields are not on the same level, eg
[[prop1.prop2.FieldA]:onEmpty(prop1.prop3.FieldB)]
which is not trivial to evaluate... and it really depends if those fields in the path is not a collection.
So my solution to such problems is, whenever possible add support for such features in your models. They you can register customized processor for your models which can do such things, since processor starts on the root object and navigates over it's properties/fields/or whatever you implement.
I've added an example on how you could implement such a feature here: https://github.com/ngs-doo/TemplaterExamples/tree/master/Intermediate/AlternativeProperty%20(Java)
Let me know if that resolves your issue
Hi @solsticesurfer If that example doesn't resolve your problem please reopen the issue
Is it possible to have a plugin like empty() to refer to another field?
For example, given two fields named "FieldA" and "FieldB", is it possible to do something like this? [[FieldA]:empty( [[FieldB]]) ]