Geetha
Occasional Observer

Get latest created page and released page

Jump to solution

Hello All,

I have the below requirement

Choose a folder where FirstSpirit takes the latest created and released page to get the content from (image (+ alt text), headline, link)

how this can be achievable in FS ? Any help?

Thank you!

1 Solution

Accepted Solutions
felix_reinhold
Returning Responder

Hi Geetha,

that's pretty straightforward:

Create a FS_REFERENCE that is filtered to pagereffolders. I call it st_folder for this example:

$CMS_SET(sv_newest_pageref, st_folder.get().getChildren(class("de.espirit.firstspirit.access.store.sitestore.PageRef"), true)

                                             .filter(pageref -> pageref.isInReleaseStore())

                                             .sort(pageref -> pageref.getReleaseRevision().getCreationTime())

                                             .last())$

$-- Now you should have the newest page from the folder. Access the FormData of its page to get the corresponding contents --$

$CMS_VALUE(sv_newest_pageref.page.formData.st_headline)$

Most of the time you're working with the pageref instead of the page therefore - that's why I implemented it with the PageRef and PageRefFolder in this case.

If you really want to use the Page, then filter the FS_REFERENCE to type pagefolder, change the class in getChildren to pagestore.Page and of course change the variable names 😉

I wrote the code directly here as acomment so I didn't test it and there might be syntax erors.

Best regards

Felix

View solution in original post

1 Reply
felix_reinhold
Returning Responder

Hi Geetha,

that's pretty straightforward:

Create a FS_REFERENCE that is filtered to pagereffolders. I call it st_folder for this example:

$CMS_SET(sv_newest_pageref, st_folder.get().getChildren(class("de.espirit.firstspirit.access.store.sitestore.PageRef"), true)

                                             .filter(pageref -> pageref.isInReleaseStore())

                                             .sort(pageref -> pageref.getReleaseRevision().getCreationTime())

                                             .last())$

$-- Now you should have the newest page from the folder. Access the FormData of its page to get the corresponding contents --$

$CMS_VALUE(sv_newest_pageref.page.formData.st_headline)$

Most of the time you're working with the pageref instead of the page therefore - that's why I implemented it with the PageRef and PageRefFolder in this case.

If you really want to use the Page, then filter the FS_REFERENCE to type pagefolder, change the class in getChildren to pagestore.Page and of course change the variable names 😉

I wrote the code directly here as acomment so I didn't test it and there might be syntax erors.

Best regards

Felix