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.

General Questions /

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

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

Controller / Template Bug?


Go to End
Reply


10 Posts   1245 Views

Avatar
dompie

Community Member, 88 Posts

11 November 2010 at 11:56pm

Edited: 12/11/2010 12:01am

Hi, I am iterating over the children of a "FolderPage" and calling a custom Method (Teaserable) on each child (which can be of different PageType). Unfortunately the method does not seem to exist.

In my Page_Controller I added this function:

   public function Teaserable(){
      return false;
   }


In the DefaultPage_Controller this function returns true (also tried this with 0/1 and strings as return values).
The layout for FolderPage.ss looks like this:

      <% if Children %>
TESTCHILDREN
      <% control Children %>
TESTCONTROL
      <% if Teaserable %>
TESTTEASER
      <h1>$Title</h1>
      <% if Last %>
      <div class="article last">
      <% else %>
      <div class="article">
      <% end_if %>
         $FirstImage.SetCropSize(355,180)
         <h2>$Title</h2>
         $ShortText
      </div>
      <% end_if %>
      <% end_control %>
      <% end_if %>


Unfortunately TESTTEASERD never got printed, why? All other (not custom) functions are available. Any hints and pints appreciated.

Avatar
swaiba

Forum Moderator, 1805 Posts

12 November 2010 at 1:03am

how about returning true?
or returning 1 and <% if Teaserable ==1 %> ?

Avatar
dompie

Community Member, 88 Posts

12 November 2010 at 3:55am

It doesn't matter what I'm returning in PHP, nothing is printed. $Teaserable produces also absolutely NO output.

Avatar
swaiba

Forum Moderator, 1805 Posts

12 November 2010 at 5:04am

put the site in dev and place a Debug::show in your function - it is likely it is not being called - if that is the case then you need to post more code to give an answer.

Avatar
dompie

Community Member, 88 Posts

12 November 2010 at 6:05am

Edited: 12/11/2010 6:08am

Thanks for replying.
I've put Debug::show('Pagename') in Teaserable, but nothing special showed up (or even happend).
The hierarchy is like:
FolderPage
   |-> Page
   |-> DefaultPage

Output generated is:
TESTCHILDREN TESTCONTROL TESTCONTROL

Page.php

class Page extends SiteTree {
   public static $has_one = array(
      'Logo' => 'Image'
   );
   public function getCMSFields(){
      $fields = parent::getCMSFields();
      return $fields;
   }
}
class Page_Controller extends ContentController {
   public function init() {
      parent::init();
      Requirements::css(DEFAULT_THEME_DIR.'/css/default.css');
   }
   /**
    * Can this page be teaserd by a folderPage
    * @return bool
    */
   public function Teaserable(){
      Debug::show('PAGE');
      return 0;
   }
}

DefaultPage.php

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

   );
   public static $has_many = array('Imageattachments' => 'DefaultPageImageattachment');
   public function getCMSFields(){
      $fields = parent::getCMSFields();
      return $fields;
   }
}
class DefaultPage_Controller extends Page_Controller {
   public function init() {
      parent::init();
      Requirements::css(DEFAULT_THEME_DIR.'/css/add.standard.css');
   }
   /**
    * Can this page be teasered by a FolderPage
    * @return bool
    */
   public function Teaserable(){
      Debug::show('DEFAULTPAGE');
      return 1;
   }
}

FolderPage.php

class FolderPage extends Page {
   public static $db = array(
      'LayoutView' => "enum('ALL_ON_ONE,ALL_AS_ACC,SUBPAGE_TSR','ALL_ON_ONE')",
      'ForwardToSubpage' => 'Boolean'
   );
   public function getCMSFields(){
      $fields = parent::getCMSFields();
      $fields->renameField('Title', _t('FolderPage.FOLDERNAME'));
      $layoutView = new DropdownField('LayoutView', _t('General.LAYOUTVIEW'), array(
            'ALL_ON_ONE' => _t('FolderPage.ALL_ON_ONE'),
            'ALL_AS_ACC' => _t('FolderPage.ALL_AS_ACC'),
            'SUBPAGE_TSR'=> _t('FolderPage.SUBPAGE_TEASER')
         ),
         'ALL_ON_ONE'
      );
      $forward = new CheckboxField('ForwardToSubpage', _t('FolderPage.FORWARD_TO_SUBPAGE'));
      $fields->addFieldToTab('Root.Content.Main', $layoutView, 'Title');
      $fields->addFieldToTab('Root.Content.Main', $forward);
      return $fields;
   }
}
class FolderPage_Controller extends Page_Controller {
   public function init() {
      parent::init();
      Requirements::css(DEFAULT_THEME_DIR.'/css/add.standard.css');
      Requirements::css(DEFAULT_THEME_DIR.'/css/add.folder.css');
   }
}

Avatar
swaiba

Forum Moderator, 1805 Posts

12 November 2010 at 10:00pm

hmmm looks like your hierarchy is more like...

Page
|-> FolderPage
|-> DefaultPage

and calling Teaserable within FolderPage.ss (i.e. FolderPage_Controller, that includes Page_Controller) is NOT going to have access to Teaserable because it is in DefaultPage_Controller.

Either move Teaserable to Page_Controller (available to all pages) or to FolderPage_Controller (available to FolderPage_Controller only).

Barry

Avatar
dompie

Community Member, 88 Posts

13 November 2010 at 1:43am

Edited: 13/11/2010 1:47am

Yes, according to class hierarchy you're absolutely right. But I was speaking about Page hierarchy in the admin sitetree, that was ambiguous.

Furthermore Teaserable already *is* in Page_Controller and is *not* available in the template.

Avatar
swaiba

Forum Moderator, 1805 Posts

13 November 2010 at 1:49am

DOH! missed that... hmmm... i see why you included the sitetree - as you are iterating over children - sorry
how about 1) adding $Teaserable to the top of the layout (just to check)
then 2) adding a Debug::show for each for the children to check what pages they are...

Go to Top