[Neos] Computed properties & JSON

Tristan Koch typo3.org at tknetwork.de
Thu Apr 2 18:57:51 CEST 2015


I need to model categories (with title, image, ...) that have products (with article number, ...). For that I defined custom document nodes (in NodeTypes.yaml) for category and product that appear like normal pages and can be edited in the Neos backend. Now, one requirement is to render products of a given category in both HTML and JSON (in case you wonder, the purpose of the JSON is to configure a JavaScript based product filter).

1) Computed node properties

The product page has a user editable property article. This property should be normalized (all lowercase, white spaces removed). I could use a processor for that, but then I would need to duplicate code when later generating the same attribute for the JSON representation. The workaround I came up with involves a custom TypoScript class that extends from TemplateImplementation. It works and properties set here can be read elsewhere. Anyway, I would much prefer to add properties to the node model itself but I don't see how.

(sorry, I'm not yet allowed to post links)

2) JSON from nodes

Eel has a JSON.stringify helper but it is very limited. The solution I came up with uses another TypoScript class and assigns a variable to the template that includes the JSON. Here I would rather like to extend the category node with a property I can call from Eel/FlowQuery that returns the JSON.

(sorry, I'm not yet allowed to post links)

I've already read most of the online documentation and some of the Neos code but I really don't see how this can be done in a cleaner way. Any hints would be greatly appreciated.


More information about the Neos mailing list