Jump to:

22994 Posts in 11843 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Controller / Template Bug?

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

Page: 1 2
Go to End
Author Topic: 994 Views
  • dompie
    Avatar
    Community Member
    88 Posts

    Controller / Template Bug? Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Controller / Template Bug? Link to this post

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

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Controller / Template Bug? Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Controller / Template Bug? Link to this post

    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.

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Controller / Template Bug? Link to this post

    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');
       }
    }

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Controller / Template Bug? Link to this post

    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

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Controller / Template Bug? Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Controller / Template Bug? Link to this post

    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...

    994 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.