Project

General

Profile

Actions

Feature #70036

closed

Fluid: Custom fallback if partial is not available

Added by Arne-Kolja Bachstein over 8 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Could have
Assignee:
Category:
Fluid
Target version:
-
Start date:
2015-09-23
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
viewhelper, fallback, partial
Complexity:
easy
Sprint Focus:

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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #69863: Use new standalone Fluid as composer dependencyClosedClaus Due2015-09-16

Actions
Actions

Also available in: Atom PDF