Viktor Livakivskyi
Viktor Livakivskyi

Reputation: 3228

TYPO3 Fluid dynamic variable part in inline if condition

I want to check for existence of configuration array in settings and, if present, pass it as argument to a partial. If it doesn't exist, pass default configuration to that partial.

My problem is, that I'm stuck at if-condition, where the check needs to be performed (then-else are simplified below):

{f:if(condition: settings.media.responsive{f:count(subject: records)}, then: 'true', else: 'false')}

Such a code is not parsed by Fluid and is simply output as is on the page. However without dynamic part it works perfectly:

{f:if(condition: settings.media.responsive1, then: 'true', else: 'false')}

Outputs true.

I've tried all possible combinations: with single-quotes and/or curly brackets around the whole condition, as well as same inside of f:count(subject), but didn't find a way to make it work.

Additionaly tried v:variable.get from VHS extension, but also without success:

{f:if(condition: {v:variable.get(name: 'settings.media.responsive{f:count(subject: records)}')}, then: 'true', else: 'false')}

The code above always results in true.

Important note: settings.media.responsive[number] contains array of settings, so can't be casted to string by surrounding it with single-quotes in condition.

Upvotes: 2

Views: 2427

Answers (1)

Claus Due
Claus Due

Reputation: 4261

If you're using the Fluid engine library:

{records -> f:variable(name: 'count')}
{f:if(condition: '{f:count(subject: \'{settings.media.responsive{count}}\')}', then: 'true', else: 'false')}

Or if you want VHS:

{f:if(condition: '{v:variable.get(name: \'settings.media.responsive{f:count(subject: records)}\') -> f:count()}', then: 'true', else: 'false')}

Upvotes: 2

Related Questions