[SOLVED] How to change a fusion prototype template path depending on a page path?

Hi,

i would like to change the template path of a prototype depending on if the user is on a special page

prototype(Vendor.Package:Type) {
    templatePath = 'resource://Vender.Package/Private/Templates/NodeTypes/Type.html'
}

That would be my condition:

`${documentNode.path == ‘/sites/mysite/node-582d89ee00807/node-582d8b8b76c1c/node-58358c603675e’}

I tried something like that but that is not working:

page.body.content.specialPage.@if.specialPage = ${documentNode.path == '/sites/mysite/node-582d89ee00807/node-582d8b8b76c1c/node-58358c603675e'}
page.body.content.specialPage.prototype(Vendor.Package:Type) {
	templatePath = 'resource://Vender.Package/Private/Templates/NodeTypes/Type.html'
    }

How can i do that?
Thank you!

Best regards
Jürgen

Hi!

You could turn templatePath into a TYPO3.TypoScript:Case:

prototype(Vendor.Package:Type) {
    templatePath = TYPO3.TypoScript:Case {
         specialPage {
              condition = ${documentNode.path == '/sites/mysite/node-582d89ee00807/node-582d8b8b76c1c/node-58358c603675e'}
              renderer = 'resource://Vendor.Package/Private/Templates/SomeSpecialTemplate.html'
         }
        default {
              @position = 'end'
              condition = true
              renderer = 'resource://Vendor.Package/Private/Templates/NodeTypes/Type.html'
        }
    }
}

Best regards
Wilhelm

EDIT: Just a tip: Use identifier rather than path, because path changes, when the document is moved.

Ah, i didnt’t thought about that solution! That’s great!
Thank you!

Nevertheless i would like to know how that would work the way i tried it.
Where do i need to hook into if i want to accomplish that if that is possible.

Well, I’m not entirely sure, what you were trying to accomplish there other than the conditional change of the template path :slight_smile:

Can you add a little more detail about your use case? I’m sure we can find a solution that better fits your context.

Best regards
Wilhelm

I wanted to tackle the “override” on a page level and not on the content element level.
After some hours of reading the documentation and going through the neos code i think i got it how the whole rendering process works. After that it wasn’t very hard to get to my desired solution :slight_smile:
I did it like that:

root.specialPage {
	condition = ${documentNode.identifier == 'e45058a1-e91d-44ee-a616-b3727732837e'}
	renderPath = '/specialPage'
}
specialPage < page
specialPage.prototype(Vendor.Package:Type) {
	templatePath = 'resource://Vendor.Package/Private/Templates/NodeTypes/Type.html'
}
1 Like

Hey @jkkleiss,

Yeah - the way you are doing it is great - I just have a little suggestion to make your code even more stable and best-practicey:

instead of doing:

page = Page {
   ... configuring page here ...
}
specialPage < page

I’d rather suggest the following:

prototype(MyPage) < prototype(TYPO3.Neos.NodeTypes:Page) {
    ... configuring page here ...
}
prototype(MySpecialPage) < prototype(MyPage) {
    ....
}

page = MyPage
specialPage = MySpecialPage

While this is a few lines more to type, it has IMHO one advantage:

  • it is more order-independent, because you inherit from a prototype; instead of copying and then modifying.

All the best,
Sebastian

1 Like