getting actual page from inherited component

35 views
Skip to first unread message

Samuli Saarinen

unread,
Dec 21, 2022, 5:56:23 AM12/21/22
to Magnolia User Mailing List
Hi,

I'm building a component that needs to access the page that it is currently on which
can normally be achieved with cmsfn.page(content) BUT if the component is inherited
then the function seems to still return the page that the component is defined even though
currently rendering a child page (that inherits the component).

Is there a way to get the "actual" page when rendering the inherited component? Or am I just trying to do something silly here? There seems to be some functions related to inheriting in cmsfn but I have not yet figured out how those could help.

BR, Samuli

Roman Kovařík

unread,
Dec 21, 2022, 7:32:14 AM12/21/22
to Magnolia User Mailing List, samuli....@gmail.com
Hey Samuli,

What does ${state.mainContentNode} return? You might want to wrap in into a ContentMap as this should return a plain JCR node.

Hope that helps
Roman

Samuli Saarinen

unread,
Dec 22, 2022, 2:29:44 AM12/22/22
to Magnolia User Mailing List, roman....@magnolia-cms.com, Samuli Saarinen
Thanks Roman, this works as I would expect in the inherited component:
[#local currentPage = (cmsfn.page(cmsfn.asContentMap(state.mainContentNode)))!{}]

It might be good to mention this in documentation also as state.mainContentNode  is only mentioned pretty briefly with no explanation on what it actually is. Also maybe cmsfn.currentPage(state) might be handy :)

Thanks for your help and merry xmas!

Samuli
Reply all
Reply to author
Forward
0 new messages