Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Controlling different pagetypes possible?


Go to End


1030 Views

Avatar
dompie

Community Member, 88 Posts

16 November 2010 at 5:20am

Last week I tried to access a function from different PageTypes inside one FolderPage (see http://silverstripe.org/general-questions/show/14811). In the end I found a workaround, but went into this problem again today. Although I was sure, this should be no problem in Silverstripe, it turns out to be somehow impossible (I believe).

My page hierarchy is as follows:
FolderPage
|-> DefaultPage
|-> Page
My class hierarchy:
Page
|-> DefaultPage
|-> FolderPage

In FolderPage I'd like to control all teaserable child pages of a FolderPage:

		<% if Children %>
		<% control Children %>
		<% if Teaserable %>
		<% if Last %>
		<div class="article last">
		<% else %>
		<div class="article">
		<% end_if %>
			$MyFirstImage
			<h2><a href="$Link">$Title</a></h2>
			$ShortText
		</div>
		<% end_if %>
		<% end_control %>
		<% end_if %>

Although $MyFirstImage exists in DefaultPage_Controller, it's not callable from Template and I can't think of any workaround for this.
Making MyFirstImage static is no solution due to required object scope (for DefaultPage.ss output). Putting MyFirstImage to DefaultPage would be almost an exact copy of the function already present in the controller (I hate that).

From FolderPage.ss I can only call functions on DefaultPage not from DefaultPage_Controller. Is there any other way I could somehow load the DefaultPage_Controller inside FolderPage_Controller or call functions of DefaultPage_Controller from FolderPage.ss? I hope this is somehow understandable.