#70036Fluid: Custom fallback if partial is not available
Description
In Extbase I have a scenario where I have to define partials based on an element type. If the partial is not available, it has to fall back to a default partial.
Imagine the following:
There are categories and items for this category. The detail view of a category’s items should be based on the category. So I have the following detail template:
<h1>{item.name}</h1>
<h2>Block 1</h2>
<f:render partial="Category/[CategoryIDorName]/DetailBlock1" />
<h2>Block 2</h2>
<f:render partial="Category/[CategoryIDorName]/DetailBlock2" />
Because there are some categories that share a default setup and some that are different from the others, I would like to have the following:
<h1>{item.name}</h1>
<h2>Block 1</h2>
<f:render partial="Category/[CategoryIDorName]/DetailBlock1" fallback="Category/Default/DetailBlock1" />
<h2>Block 2</h2>
<f:render partial="Category/[CategoryIDorName]/DetailBlock2" fallback="Category/Default/DetailBlock2" />
This cannot be solved by the existing path overlay feature, as it would try to get the partial from a folder with the same name.
Currently I solved this by using a custom ViewHelper, wrapped in an if-statement:
<f:if condition="{krbu:PartialExists(partial: 'Category/{item.id}/DetailBlock1')}">
<f:then><f:render partial="Category/{item.id}/DetailBlock1" arguments="{_all}" /></f:then>
<f:else><f:render partial="Category/Default/DetailBlock1" arguments="{_all}" /></f:else>
</f:if>
But I think, that adding a simple fallback argument to the existing render ViewHelper would be the cleanest solution and I think, this might be of use for a lot of implementers.
Unfortunately I could not understand the view/partial flow very good yet without moderation, so I wasn’t able to just create a patch for it.