Manipulate style-tag in head-tag out of NodeType

Hi together,
I would like to combine the Image-Skills from Neos with responsive Design-Solution in more flexible form.
##What works currently:##

I found a solution to generate a <style> tag in <head> and it works for direct subNodeTypes from ContentCollection or other exactly predefined situations with:

${q(node).children('[instanceof TYPO3.Neos:ContentCollection]').children('[instanceof Vendor.Site:PredefinedNodeType]').add(*otherTypeSelection*)}

#Result in HTML:
@media screen {#id .class{ background-image: url('//website.neos/_Resources/Persistent/ec0fee7d5a7722671bfb78166ea9862411a03b77/image.jpg') } 
@media screen and (min-width: 40em), screen and (....

##What is missing: more flexible solution##
For a more flexible solution (usable for all existing elements of a particular nodeType no matter where in the pageStructure but only in the current Page) I stumble over the impossibility to limit an FlowQuery’s find() to ONLY the current page/document without subPages/subDocuments. I can’t find the solution to exclude subpages.

It seems, this limitation is not provided. Maybe my approach is wrong and there is an more easy way from an other direction.

##Different approach/thinking and questions:##

- Is it possible to manipulate/add the <style> tag in <head> from an .ts2-Fusion/TypoScript File related to an NodeType?

#something like: 
prototype(SpecialNodeType) < prototype(TYPO3.Neos:Content) {
    page.head.style.@process.addNewLine = ${ value + "newLineAsString"}
}
```
I tried it in different manner, but I can't find a solution for...
(I guess: it cause on the building-sequence of neos-Sites . Most likely the page.head.style is builded before SpecialNodeType related elements.)
<small>But I'm not sure about. Can't find a building-sequence-flowChart or something similar. The NeosSourceCode is to complicated for me to understand/find the sequence of Neos' CodeProcessing and stepByStep debug and anyway break-points in fusion/typoScript are not possible</small>

***- Is it possible to store some value in included NodeType-related Fusion-Prototypes  for combine it later on in root.ts2?***
Maybe with @context? I can't find a working solution with ...
<small> Maybe the same problem like above with build-sequence, but I'm not sure and maybe it's I have a completely wrong understanding of Neos' internal sequence of code-processing... Maybe there would be a totally simple solution for.</small>


***- Is there an other approach to process/find all used elements of one particular nodeType in current Page only (without subpages)?***


Would be great if someone could push me in the right direction...
Thanks Martin

That is not the intention of fusion/ts2. The main idea is having a side effect free rendering to allow rerendering of separately cached parts at any time. Manipulating the header by rendering a content somewhere in the page would be a real bad side-effect, same goes for passing values around via ts.

Offcourse you are free to do such stuff … maybe add a viewHelper or TS Object that stores some value and an HTTP: Component that adds code to the header after rendering. That is perfectly possible but will break your as soon as your content-section is rerendered but the cache entry for the document is not.

Usually it helps to start with the main collection to find content-nodes but not the child-documents:

mySpecialNodes = ${q(documentNode)->children('main')->find('[instanceof Vendor.Site:SpecialNodeType]')}

Another approach would be to look into all ContentCollections that are the direct children of your document:

mySpecialNodes = ${q(documentNode)->children('[instanceof TYPO3.Neos:ContentCollection]')->find('[instanceof Vendor.Site:SpecialNodeType]')}

as usual … beware of typos in the code above

1 Like

Wouw,
shamefully simple when I look at it — now.
Why I do not think to limit find() to all existing subelements of current page before run the flowQueryFunction…

Great!
With:

prototype(Vendor.Site:MetaStyle) < prototype(TYPO3.TypoScript:Template){
    bunchOfSpecialNodeType = {${q(documentNode).children('[instanceof TYPO3.Neos:ContentCollection]').find('[instanceof Vendor.Site:SpecialNodeType]')}
}
```
I only get the desired Nodes from type SpecialNodeType within the current page and all the subpage nodes are omitted.

Bingo! and thank you very much - Now it works like a charm without side-effects!
1 Like