we have different users (different domain models), and I have to tell them apart in the templates.
It would be fine to have something like the instanceOf operator in Fluid.
I don’t found a solution, so I added the property “userType” to the models as a work around.
It works fine- but I don’t like.
I would just like to suggest something a bit different. IMHO rather implement a x:instanceOf ViewHelper that returns a boolean and use the “normal” f:if ViewHelper instead of implementing a custom ifInstanceOf. I would discourage that in general.
sounds more universal to me.
This gives me a new Idea:
I will try out a x:format.classname ViewHelper, whitch accepts an object and delivers the class name.
Also instead of switch I would rather use partials and dynamically decide the partial name based on class or raher some type property in the class(es).
Besides I think that using a ViewHelper that doesn’t actually render a string already suggests that it does some logic that should be moved somewhere else.
Speaking of which: @energyWinner can you describe your high-level requirements a little bit?
I’m sure you can solve this much easier and more flexible with polymorphism
Sure, I actually have two arguments that I feel make this the better best practice choice:
It’s way more flexible. See below, if at some point you notice a if/else doesn’t cut it you can just reuse the VH in a case, no problem there.
easier/performance. Writing a condition VH (and especially a fast condition ViewHelper) is not easy. I took quite some time optimising the existing if VH. Writing an simple bool providing VH is easy and can also be optimised quickly. So I prefer people doing that and benefitting from the optimised if VH automatically.
It’s for me more in line with thinking in simple helpers strung together to do something complicated instead of doing it all in one big tihng.