Get content from body.content (and count words)

Hi there,

I want (well, Google Analytics’ data layer wants) to count the words in the content area. This is quite easy:

textLength = Neos.Neos:PrimaryContent {
    nodePath = 'main'
    @process.count = ${String.wordCount(String.stripTags(value))}
}

But my page has a feature (nodePath) and more keys below body.content.

Something like this:

prototype(Neos.NodeTypes:Page) {
    body {
        content {
            feature = Neos.Neos:PrimaryContent {
                nodePath = 'feature'
            }

            main = Neos.Neos:PrimaryContent {
                nodePath = 'main'
            }

            product = Neos.Neos:Content {
                templatePath = 'resource://...'
            }
        }
    }
}

Is it possible to get the value from body.content so I can strip tags and count the words?

idk where you want to have the counted words in your sites markup, but this will do if you want to display the wordcount above the content:

prototype(Neos.NodeTypes:Page) {
    body {
        content {
            feature = Neos.Neos:PrimaryContent {
                nodePath = 'feature'
            }

            main = Neos.Neos:PrimaryContent {
                nodePath = 'main'
            }

            product = Neos.Neos:Content {
                templatePath = 'resource://...'
            }
        }
        @process.addCount = afx`
            <p>Words: {String.wordCount(String.stripTags(value))}</p>
            {value}
        `
    }
}

Thanks Marc! Important information missing. :no_mouth:
I need to render it in the head.

Something like this:

prototype(Neos.NodeTypes:Page) {
    head {
        dataLayerBase = Neos.Fusion:Component {
            data = Neos.Fusion:DataStructure {
                event = 'init'

                page = Neos.Fusion:DataStructure {
                    categoryPath = ${categoryPath}
                    type = ${type}
                    country = ${country}
                    language = ${language}
                    text-length = Neos.Neos:PrimaryContent {
                        nodePath = 'main'
                        @process.count = ${String.wordCount(String.stripTags(value))}
                    }
                }
            }

            dataJson = ${Json.stringify(this.data)}

            renderer = afx`
                <script>
                    window.dataLayer = window.dataLayer || [];
                    window.dataLayer.push({props.dataJson});
                </script>
            `
        }
    }
}

how about:

text-length = Neos.Fusion:Join {
        Neos.Neos:PrimaryContent {
            nodePath = 'feature
        }
        main = Neos.Neos:PrimaryContent {
            nodePath = 'main'
        }

        product = Neos.Neos:Content {
            templatePath = 'resource://...'
        }
        @process.addCount = ${String.wordCount(String.stripTags(value))}
}

but make sure you dont need to query the content twice internal (when you want to display the actual text too), that would cost speed