Overriding the default value of childNodes


(George Dimitriadis) #1

Hello,

I have a few childNodes in my Page NodeType and I want to also pass a default value to them, is it possible to do this through yaml or alternatively in fusion ?

Specifically, consider the following NodeTypes.yaml

'Neos.NodeTypes:Page':
  childNodes:
    'aboutTeaserTitleLeft':
      type: 'Vendor.Site:Text'

'Vendor.Site:text':
  superTypes:
    'Neos.NodeTypes:Text': TRUE

(The reason I am using another NodeType instead of Neos.NodeTypes:Text directly is that I am overriding the rendered template in fusion).

Then I am configuring this child node with my custom prototype in fusion as descibed here, which in simple code would look like this:

aboutTeaserTitleLeft = Neos.Fusion:Collection {
    itemName = 'node'
    collection = ${q(node).children('aboutTeaserTitleLeft')}
    itemRenderer = Neos.Neos:ContentCase
}

Now, everything is alright, but when my node is empty I see a floating “Enter text here” placeholder, but instead of that I would like to render the field with a default value which I can specify to be different every time I use this child node. How can I do this ? I tried adding the defaultValue under the childNode definition in yaml but didn’t help:

'Neos.NodeTypes:Page':
  childNodes:
    'aboutTeaserTitleLeft':
      type: 'Vendor.Site:Text'
      properties:
        text:
          defaultValue: 'My default'

Thanks in advance !


(Maximilian Schmidt) #2

You can’t pass values in the yaml-configuration, but you can do with Fusion.
In your Vendor.Site:text Fusion file you could do something like this:

...
text = ${q(node).property('text') != null ? q(node).property('text') : 'my default value'}
...

or either use a Neos.Fusion:Case object for the fusion property:

...
text = Neos.Fusion:Case {
  hasText {
    condition = ${q(node).property('text') != null}
    renderer = ${q(node).property('text')}
  }
  default {
    condition = ${true}
    renderer = 'my default value'
  }
}

If you don’t use it as template variable let me know, then I can provide another solution fitting your case.


(George Dimitriadis) #3

Hi Maximillian,

thanks for your help, but while rendering the default value, I am not able to edit it. Am I doing something wrong ?

I can’t find where the renderer is defined, but maybe I have to override the renderer default value instead of the whole renderer object or whatever it is that renders my variable as editable in the backend ?

This is my code adjusted to your suggestion:

aboutTeaserTitleLeft = Neos.Fusion:Collection {
    itemName = 'node'
    collection = ${q(node).children('aboutTeaserTitleLeft')}
    itemRenderer = Neos.Fusion:Case {
        hasText {
            condition = ${q(node).property('text') != null}
            renderer = ${q(node).property('text')}
        }
        default {
            condition = ${true}
            renderer = 'my default value'
        }
    }
}

(George Dimitriadis) #4

And again this same problem happens when I try to extend the TwoColumn NodeType like this:

'Vendor.Site:TwoColumn':
  superTypes:
    'Neos.NodeTypes:TwoColumn': TRUE
  properties:
    layout:
      defaultValue: '26-34'
      ui:
        reloadIfChanged: TRUE
        inspector:
          editorOptions:
            values:
              parentNode: [ ]
              '26-34':
                label: '43% / 57%'
              '34-26':
                label: '57% / 43%'

'Neos.NodeTypes:Page':
  childNodes:
    'main':
      constraints:
        nodeTypes:
          '*': FALSE
          'Vendor.Site:TwoColumn': TRUE

I added parentNode: [ ] like the documentation suggests and this just results in an extra empty option in the select box. I also tried replacing parentNode with ‘Neos.NodeTypes:TwoColumn’ without success. I’m sure this is doable through the configuration, the documentation says it, maybe the syntax changed ?


[SOLVED] Remove properties from NodeType of included package
(Maximilian Schmidt) #5

You can’t edit the default value since it is defined through Fusion during the rendering process, but is not stored anywhere. Maybe you could explain you use case a bit more detailed.
If you try to use the default value as placeholder for editing in backend, you can set a placeholder for aloha. (This is actually not documented at readthedocs.io)

property:
  ui:
    aloha:
      placeholder: 'Enter title here'

Here you can just render an editable Tag like this:

text = Neos.Fusion:Tag {
  tagName = 'div'
  content = ${q(node).property('property')
  @process.edit = ContentElementEditable {
    property = 'property'
  }
}

If you also want your default Value to be rendered if nothing is specified within the backend you have to change your Fusion code to:

text = Neos.Fusion:Case {
  value {
    condition = ${q(node).property('property') != null || node.context.inBackend == true}
    renderer = Neos.Fusion:Tag {
      tagName = 'div'
      content = ${q(node).property('property')}
      @process.edit = ContentElementEditable {
        property = 'property'
      }
    }
  }
  default {
    condition = ${true}
    renderer = Neos.Fusion:Tag {
      tagName = 'div'
      content = 'My cool default value'
    }
  }
}
```

Like this it should work. If it still doesn't maybe I got your explanation wrong.
Now it renders the Tag with the actual set content or with the default value in live, while always rendering the editable version in backend.