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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Reading contents of files

Go to End

3 Posts   829 Views


Community Member, 26 Posts

9 March 2010 at 1:43pm

Hi there,

I have an existing website that generates a footer based on the titles of the pages in the footer. The pages in the footer are not related by hierarchy in any way so I can't use the Menu() template control. Let's the say the footer looks like:


I know I can use the Page control in the template like:

<% control Page('home') %>$Title<% end_control %> | .... | <% control Page('employee') %>$Title<% end_control %>

but I'd rather hide the logic in the class so I can output the footer like this:


What do you recommend? How can I access the contents (eg, title, menu title) of pages within a class using a method in the controller:

method Footer() {
$footer = '';
$footer_files = array('home', ...., 'employee');
foreach ($footer_files as $file) {
// read the contents of each file here;
$footer = ...?
return $footer;

(as background info, the site is currently running on MODx where we used the Ditto and WayFinder snippet to generate the footer. It's basically just a file content reader that you pass a list of page ids to that you want to read content of fields from. We want to be able to duplicate this functionality in SilverStripe)



Forum Moderator, 5523 Posts

9 March 2010 at 2:43pm

Welcome to the forums!.

I guess if you were going to use <% control Page() %> then the urls would have to be the same so what you can do is

function Footer() {
$urls = array('page-1', 'page-2', 'page-3'); // in the order you need;

$output = new DataObjectSet();

foreach($urls as $url) {
$page = DataObject::get_one('Page', "URLSegment = '$url');

if($page) $output->push($page);

return $output;

// in the template
<% control Footer %>
<a href="$Link">$MenuTitle</a>
<% end_control %>

Hope that helps!. Another option you have.


Community Member, 26 Posts

9 March 2010 at 6:18pm

Thanks so much for the welcome and speedy response Wilr! That is exactly what I was looking for.

I don't think this next question is possible because of the code base and also because it violates separation of logic from display, but I'll ask anyways. Is it possible to actually pass the page url into the Footer method from the template? (this type of functionality is also used elsewhere besides the footer and I'd like to have this one 'generic' method that can be shared). If not, I can make this method as generic as possible, eg, call it contentReader(array), then have methods like Footer( array('page1', 'page2', etc.) ) and Header( array('page3', 'page4', 'page5') ) that will call contentReader().

thanks again!