Skip to content

Instantly share code, notes, and snippets.

@danielkoch
Last active March 31, 2016 18:05
Show Gist options
  • Save danielkoch/f779c82570eccbff5999 to your computer and use it in GitHub Desktop.
Save danielkoch/f779c82570eccbff5999 to your computer and use it in GitHub Desktop.
<f:section name="Main">
<f:for each="{content}" as="itemSectionObject" key="key" iteration="iteration">
<v:variable.set name="?" />
<v:variable.set name="?" />
<fed:data.var name="objectType" value="{fed:data.func(func: 'key', arguments: {0: itemSectionObject})}" />
<fed:data.var name="object" value="{fed:data.func(func: 'array_pop', arguments: {0: itemSectionObject})}" />
<v:switch value="{objectType}">
<v:case case="content1" break="TRUE">
RENDER CONTENT1
</v:case>
<v:case case="content2" break="TRUE">
RENDER CONTENT2
</v:case>
</v:switch>
</f:for>
</f:section>
@bjo3rnf
Copy link

bjo3rnf commented Mar 28, 2016

Hi Daniel,

is content an array of arrays, i. e. itemSectionObject is an array?

Cheers
Björn

@bjo3rnf
Copy link

bjo3rnf commented Mar 28, 2016

{itemSectionObject -> v:iterator.keys() -> v:iterator.shift() -> v:variable.set(name: 'objectType')}
{ItemSectionObject -> v:iterator.pop() -> v:variable.set(name: 'object')}

@danielkoch
Copy link
Author

Hi Björn,

I missed your comment here.

{content} is an array of arrays, yes:
array(1 item) 1 => array(1 item) content1 => array(5 items) disabled => '0' (1 chars) insideheadline => 'Meine Unterüberschrift' (23 chars) tag => 'h2' (2 chars) underline => '0' (1 chars) id => '4a5457497350a8bde5650d4e57250f29ab76fdea' (40 chars)

colored dump

If I use your two lines I get the following error:

Unsupported input type; cannot convert to array!

Thanks,
Daniel

@bjo3rnf
Copy link

bjo3rnf commented Mar 31, 2016

Hi Daniel,

did you notice the typo in the second line (capital 'i')? That's what the error comes from maybe. Do you need the variable 'object' at all?

Cheers
Björn

@bjo3rnf
Copy link

bjo3rnf commented Mar 31, 2016

I think this should work to get the actual object data (untested as well): {v:variable.get(name: 'itemSectionObject.{objectType}') -> v:variable.set(name: 'object')}

@bjo3rnf
Copy link

bjo3rnf commented Mar 31, 2016

This is quite ugly though. How does the array look like in full? Can there be more than one entry below key '1'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment