Reputation: 85
I am using Silverstripe and i am really confused. I created Holder and Page class and theirs .ss files.
mysite/code/NewsPage.php
class NewsPage extends Page {
static $db = array('Date' => 'Date', 'Author' => 'Text');
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields -> addFieldToTab('Root.Main', $dateField = new DateField('Date', 'Date'), 'Content');
$dateField -> setConfig('showcalendar', true);
$fields -> addFieldToTab('Root.Main', new TextField('Author', 'Article author'), 'Content');
return $fields;
}
}
class NewsPage_Controller extends Page_Controller {
public function init() {
parent::init();
}
}
mysite/code/NewsHolder.php
class NewsHolder extends Page {
static $allowed_children = array('NewsPage');
}
class NewsHolder_Controller extends Page_Controller {
public function NewsList() {
$holder = NewsHolder::get()->filter('ID', $this->ID);
return ($holder) ? NewsPage::get()->filter('ParentID', $this->ID)->sort('Date DESC')->limit(3) : false;
}
}
templates/Layout/NewsPage.ss
<article>
<h2>$Title</h2>
<div class="content">
$Content
</div>
<p class="author">
$Author
</p>
<p class="info">
$Date.Format("d.m.Y")
</p>
</article>
templates/Layout/NewsHolder.ss
<% loop $NewsList %>
<article>
<h2><a href="$Link">$Title</a></h2>
<p class="demo">
$Content.FirstParagraph ...
</p>
</article>
<% end_loop %>
These classes is for articles and works fine. I copied these codes for GalleryPage and GalleryHolder which I want for pictures. The problem is that Silverstripe do not use GalleryHolder.ss but default Page.ss template.
I cannot figure out why. For NewsPage.ss and NewsHolder.ss it works fine, but exactly same code in another classes (GalleryPage and GalleryHolder) use default Page.ss. Code is the same, I just changed all NewsPage or NewsHolder strings to GalleryPage and GalleryHolder.
Edit : copied code for Gallery pages
mysite/code/GalPage.php
class GalPage extends Page {
static $db = array('Date' => 'Date', 'Author' => 'Text');
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields -> addFieldToTab('Root.Main', $dateField = new DateField('Date', 'Date'), 'Content');
$dateField -> setConfig('showcalendar', true);
$fields -> addFieldToTab('Root.Main', new TextField('Author', 'Article author'), 'Content');
return $fields;
}
}
class GalPage_Controller extends Page_Controller {
public function init() {
parent::init();
}
}
mysite/code/GalHolder.php
<?php
class GalHolder extends Page {
static $allowed_children = array('GalPage');
}
class GalHolder_Controller extends Page_Controller {
public function NewsssList() {
$holder = GalHolder::get()->filter('ID', $this->ID);
return ($holder) ? GalPage::get()->filter('ParentID', $this->ID)->sort('Date DESC')->limit(3) : false;
}
}
templates/Layout/GalPage.ss
<article>
<h2>$Title</h2>
<div class="content">
$Content
</div>
<p class="author">
$Author
</p>
<p class="info">
$Date.Format("d.m.Y")
</p>
</article>
templates/Layout/GalHolder.ss
<% loop $NewsssList %>
<article>
<h2><a href="$Link">$Title</a></h2>
<p class="demo">
$Content.FirstParagraph ...
</p>
</article>
<% end_loop %>
Can you please give me some advice how to fix the problem ?
Upvotes: 0
Views: 2529
Reputation: 2256
As 3dgoo said - have you placed the template files within the themes directory? Also, sometimes manually clearing the cache (i.e. delete the files in silvestripe-cache folder) helps.
Upvotes: 2