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

Can't Get $Layout Working


Go to End


4 Posts   1095 Views

Avatar
goodness

Community Member, 38 Posts

5 April 2013 at 8:42am

Hi All,

I'm brand new to SS and working my way through the tutorial. I was finally able to get the system to recognize a new HomePage page type.
However, I can't seem to get the $Layout piece to work. When I replaced everything in the <div id="ContentContainer"> with $Layout nothing renders in the pages.

I am running version 3.0.5

Here's my code:

templates/Page.ss

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<% base_tag %>
<title><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title>
<meta charset="utf-8">
$MetaTags
<% require themedCSS(layout) %>
<% require themedCSS(typography) %>
<% require themedCSS(form) %>
<title></title>
<link rel="stylesheet" type="text/css" href="tutorial/css/layout.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/typography.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/form.css" />
</head>
<body>
<div id="Main">

<div id="BrandingTop"></div>
<div id="BrandingBtm">
<div id="SecureLogin"></div>
</div>

<div id="TopNavHolder">
<ul id="Menu1">
<% control Menu(1) %>
<li class="$LinkingMode">
<a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a>
</li>
<% end_control %>
</ul>
</div>

<div id="Header">
<h1>$Title</h1>
</div>

<div id="ContentContainer">
$Layout
</div>

<div id="Footer">
<span>Visit <a href="http://www.silverstripe.com" title="Visit www.silverstripe.com">www.silverstripe.com</a>; to download the CMS</span>
</div>
</div>
$SilverStripeNavigator
</body>
</html>

templates/Layout/Page.ss

<% if Menu(2) %>
<ul id="Menu2">
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>

<div id="Content" class="typography">
<% if Level(2) %>
<div class="breadcrumbs">
$Breadcrumbs
</div>
<% end_if %>
$Content
$Form
</div>

code/Page.php

<?php
class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
);

}
class Page_Controller extends ContentController {

/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* array (
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* );
* </code>
*
* @var array
*/
public static $allowed_actions = array (
);

public function init() {
parent::init();

// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS('reset');
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}

}

I have removed the HomePage.ss file from the templates folder. I do, however have a HomePage.ss file in Layout.
Here's that code:

templates/Layout/HomePage.ss

<div id="Banner">
<img src="themes/tutorial/images/welcome.png" alt="Homepage image" />
</div>
<div id="Content" class="typography">
$Content
</div>

I also have a HomePage.php file in the code folder.

Here's that code:

code/HomePage.php

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);
}

class HomePage_Controller extends Page_Controller {

}

I have run both the ?flush=1 and dev/build

Any/all help is greatly appreciated.

Thanks!

Avatar
zenmonkey

Community Member, 545 Posts

11 April 2013 at 1:31pm

Do you get a blank page or just an empty ContentContainer?

Also try adding ?isDev=1 to your URL to see if throws an error

As an aside, if you're using 3.0.5 I'd start using the <% loop {method] %><% end_loop %> instead of <% control {method} %><% end_control %> as control is depreicated and may loose support in the future

Avatar
goodness

Community Member, 38 Posts

13 April 2013 at 7:47am

Edited: 13/04/2013 7:49am

zenmonkey - Thank you for responding! The weird thing is -- I was having this issue when using the Tutorial theme. When I switched to the Simple theme everything worked fine.

Oh - as an FYI I was getting an empty ContentContainer. The page was rendering. It was just empty.

Thanks again!

Avatar
RuthAdele

Community Member, 21 Posts

27 April 2013 at 9:27pm

Sounds like you just needed to run ?flush=1 on the page.