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.

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

Tutorial 2 SS is not using the currect templates?


Go to End


7 Posts   1812 Views

Avatar
TF-35Lightning

Community Member, 137 Posts

8 April 2010 at 1:02pm

Edited: 08/04/2010 2:03pm

Hi all,

I am attempting to go through Tutorial 2 of SS
http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site

Now I've got all the .ss and .php pages setup.

mysite\code\ArticleHolder.php
mysite\code\ArticlePage.php
mysite\code\HomePage.php

themes\tutorials\templates\Layouts\ArticleHolder.ss
themes\tutorials\templates\Layouts\ArticlePage.ss
themes\tutorials\templates\Layouts\HomePage.ss

Have done the dev flush, flush all etc
I can create a Article, Holder, Article Page or Homepage in the admin and under behaviour page type it will show whatever I have selected.
But back on the front end none of these templates appear to be being used.

I debug by going:
?showtemplate=1

and it always shows
themes.tutorial.templates.Page.ss

So my created templates aren't actually being used on the front end.

Heres my class files also:

mysite\code\ArticleHolder.php
<?php
/**
* Defines the ArticleHolder page type
*/
class ArticleHolder extends Page {
static $db = array(
);
static $has_one = array(
);

static $allowed_children = array('ArticlePage');
}

class ArticleHolder_Controller extends Page_Controller {

}

?>

mysite\code\ArticlePage.php
<?php
class ArticlePage extends Page {

static $db = array(
'Date' => 'Date',
'Author' => 'Text'
);

static $icon = "themes/tutorial/images/treeicons/news";

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

return $fields;

}
}

class ArticlePage_Controller extends Page_Controller {

}

?>

mysite\code\HomePage.php
<?php
/**
* Defines the HomePage page type
*/

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

static $icon = "themes/tutorial/images/treeicons/home";

}

class HomePage_Controller extends Page_Controller {

function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

}

?>

Any help would be great

Avatar
Willr

Forum Moderator, 5523 Posts

8 April 2010 at 4:17pm

Note your Layouts folder should be called 'Layout'

Avatar
TF-35Lightning

Community Member, 137 Posts

8 April 2010 at 4:20pm

Hi Will

Sorry that was a typo the directory structure is indeed

themes\tutorial\templates\Layout

Any other ideas?

Avatar
Willr

Forum Moderator, 5523 Posts

8 April 2010 at 4:25pm

Make sure you have done a ?flush=1 and your Page.ss contains a $Layout variable for getting the subtemplates in the layout folder.

Avatar
TF-35Lightning

Community Member, 137 Posts

8 April 2010 at 4:37pm

Will I think $Layout might be my problem.

Where should that sit in the Page.ss file?

Here's my Page.ss

<?xml version="1.0" encoding="UTF-8"?>
<!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 %>
$MetaTags
<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">
<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 id="Header">
<h1>$Title</h1>
</div>
<div id="ContentContainer">
<% 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>
</div>

<div class="newsDetails">
Posted on $Date.Nice by $Author
</div>
$PageComments

<div id="Footer">
<span>This is PAGE.SS Visit <a href="http://www.silverstripe.com" title="Visit www.silverstripe.com">www.silverstripe.com</a>; to download the CMS

<table width="175" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td>&nbsp;</td>
</tr>
</table>

</span>
</div>
</div>
$SilverStripeNavigator

</body>
</html>

Avatar
TF-35Lightning

Community Member, 137 Posts

8 April 2010 at 6:34pm

Okay I found out why the template werent loading and that was because of my not reading the subtemplate section of tutorial 1.

Now that I have that all worked out, my templates load however on the Article Holder summary I just get nothing showing its blank.

Do I have to load the Article Pages in a specific way??? I have 5 top level Article Pages there, but as I said they arent shown in the Articel Holder page.

Avatar
TF-35Lightning

Community Member, 137 Posts

8 April 2010 at 7:14pm

Don't worry Will got it all worked out and I am now cooking with gas. (I had to load the Article Pages underneath the Article Holder, not at the top level.)