nodePath with Condition?

Hey,

I have a short question.
I created a new content-element to display different column types. The difference to the already existing column-element is that the different columns are displayed in one element. So I have for example up to five cols and for each col a nodePath.

When you are in the backend I only want to display the nodePaths in the tree which are activated. Is there an option to integrate something like a condition for each nodePath in the following code:

prototype(MO.MyOnepage:ColumnElement) { columnOne = TYPO3.Neos:ContentCollection { nodePath = 'columnone' } columnTwo = TYPO3.Neos:ContentCollection { nodePath = 'columntwo' } columnThree = TYPO3.Neos:ContentCollection { nodePath = 'columnthree' } columnFour = TYPO3.Neos:ContentCollection { nodePath = 'columnfour' } columnFive = TYPO3.Neos:ContentCollection { nodePath = 'columnfive' } }

Greetings, David

Hard to give you clear advice without knowing how your node type is configured (NodeTypes.yaml), but you can add a property “numberOfColumn” with a select editor, with value 1,2,3,4,5 and change your TS:

prototype(MO.MyOnepage:ColumnElement) {
    @context.numberOfColumn = ${q(node).property('numberOfColumn')}
    columnOne = TYPO3.Neos:ContentCollection { 
        nodePath = 'columnone'
        @if.isVisible = ${numberOfColumn >= numberOfColumn}
    } 
    columnTwo = TYPO3.Neos:ContentCollection { 
        nodePath = 'columntwo' 
        @if.isVisible = ${numberOfColumn >= numberOfColumn}
    } 
    columnThree = TYPO3.Neos:ContentCollection { 
        nodePath = 'columnthree'
        @if.isVisible = ${numberOfColumn >= numberOfColumn}
    } 
}

You can even refactor a bit:

prototype(MO.MyOnepage:Column) < prototype(TYPO3.Neos:ContentCollection) {
        @if.isVisible = ${numberOfColumn >= numberOfColumn}

}

prototype(MO.MyOnepage:ColumnElement) {
    @context.numberOfColumn = ${q(node).property('numberOfColumn')}
    columnOne = MO.MyOnepage:Column { 
        nodePath = 'columnone'
    } 
    columnTwo = MO.MyOnepage:Column { 
        nodePath = 'columntwo' 
    } 
    columnThree = MO.MyOnepage:Column { 
        nodePath = 'columnthree'
    } 
}

TLDR, TS outputed from my brain without testing, but should work

From my perspective it’s always better to avoid element configuration, like numberOfColumn and provide multiple node type like we do in the default node types. It’s more easy to the editor. And by example in your case the content inspector (bellow the navigate component), will always show 5 sub content collection, and maybe subcontent, that are not visible / used in the page, that can cause bad UX.

My rule of thumb is always avoid configuration is a custom node type can make the experience more easy for the editor. Like I need 4 columns, I select the “4 columns element”, is way more easy that "I select the magic column element, go to the inspector select the correct group and change the amount of column I need … and I understand that the content inspector do not show me the real content I have on the page, …)

And yes discuss support code highlight, just start the line with 4 spaces caracters

Bests,

Thank you for your detailed reply and for the assistance. Good to know that this is possible. Regarding the content elements for columns, I give you right. It will probably be wiser to split it up. :wink:

Regards, David

1 Like