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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Problem creating subtemplates


Reply


5 Posts   1500 Views

Avatar
jest

Community Member, 6 Posts

7 October 2008 at 10:36am

Hi there

Silverstripe newbie here, am working my way through Tutorial 1, and although I've managed to create new page types, I have run into a problem with the subtemplates.

Am trying to customise my own theme, so am working out of "mydomain/silverstripe/bluetheme/templates" folder. Have created a "AboutUsPage.php" file with the extend Page and extend Page Controller bit, uploaded into the "MySite/Code" folder. Created a "AboutUsPage.ss" in the "mydomain/silverstripe/bluetheme/templates/Layout" folder and that worked fine.

However, when I tried to introduce a new template variable "Banner" into the main "Page.ss" under "mydomain/silverstripe/bluetheme/templates" folder, and created the Banner folder with the appropriate "Page.ss" and "AboutUsPage.ss" in it, the information does not show up.

I've flushed the database, cms and amended pages, but still no joy. Changed the name of the template variable to "Star", still not working.

Just wondering, do I need to define my new template variable anywhere in the Silverstripe cms, or does it do it automatically?

Also, just wanted to check that this should work from the "theme" directory and not from the "Mysite" directory, right?

I'm sure I've just missed something really basic. Have double checked all my upper and lowercase spellings this time. Any help would be most appreciated.

J.
Will finish this tutorial even if it kills me.

Avatar
Willr

Forum Moderator, 5513 Posts

7 October 2008 at 11:38am

when I tried to introduce a new template variable "Banner"

What do you mean by template variable? Are you trying to create a new Page Type? Each template must point to a Page Type file. Each variable within the template eg ($Title, $Content..) must point to a function or a database field in that page type.

Avatar
jest

Community Member, 6 Posts

7 October 2008 at 11:56am

Have created a new Page Type "AboutUsPage", which shows up in the CMS.
In the main "Page.ss" in the templates folder, I am trying to introduce a new template variable $Banner into the div header bit:

<div id="Header">
   $Banner
</div>

much like

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

I have created a "mydomain/silverstripe/bluetheme/templates/Banner" folder with Page.ss and AboutUsPage.ss with different header content in it, but the resultant page turns up a blank section where the $Banner information should be. It is as though the page isn't recognising my new variable "Banner", hence I'm wondering if I need to add the "Banner" variable to a list of variables anywhere?

Cheers
J.

Avatar
Willr

Forum Moderator, 5513 Posts

7 October 2008 at 12:09pm

What you are trying to do cannot be done, it doesn't work like that Im afraid. $Layout is special in how it looks for subtemplates. What is it you are trying to output to Banner?

If you want a variable $Banner you must add a database field to Page.php eg

// Defines Banner in the Database, does not add it to the CMS though
static $db = array(
'Banner' => 'Image'
);

Then in the templates you can use $Banner to output the image. Or you can have $Banner as a function in Page.php -> Page_Controller

function Banner() {
return "<img src='banner.jpg' />";
}

Avatar
jest

Community Member, 6 Posts

7 October 2008 at 12:24pm

Hi willr

Thanks for clarifying that, am not going totally crazy after all.
I've got about 7 main sections in which I was trying to change the top image in the header bit and thought I could create a subtemplate for that becaused it's just a small bit of code.
No matter, will work around that by creating different page types for the different sections.

Thanks for your time.

J.
Finished tutorial 1 and still alive.