Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » More template woes

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
Go to End
Author Topic: 309 Views
  • alana
    Avatar
    Community Member
    7 Posts

    More template woes Link to this post

    Hi,

    My stuggle with even the most basic of concepts goes on, I find it painfully frustrating that a couple of weeks into using SS I am still having issues with templates. If anyone can shine any light on this issue I would appreciate it:

    WhatsonHolder.php:

    <?php

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    class WhatsonsHolder extends Page {

    private static $allowed_children = array(
    'Whatson'
    );
          
    }

    class WhatsonsHolder_Controller extends Page_Controller {
       
    }

    ?>

    WhatsOn.php

    <?php

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    class Whatson extends Page {

    private static $has_many = array(
    'Shows' => 'Show'
    );

    function getInfo() {
    return $this->renderWith("Shows");
    }

    public function getCMSFields() {
    // Get the fields from the parent implementation
    $fields = parent::getCMSFields();
    // Create a default configuration for the new GridField, allowing record editing
    $config = GridFieldConfig_RelationEditor::create();
    // Set the names and data for our gridfield columns
    $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
    'Name' => 'Name',
    'Whatson.Title'=> 'Whatson' // Retrieve from a has-one relationship
    ));
    // Create a gridfield to hold the show relationship
    $showsField = new GridField(
    'Shows', // Field name
    'Show', // Field title
    $this->Shows(), // List of all related shows
    $config
    );
    // Create a tab named "Shows" and add our field to it
    $fields->addFieldToTab('Root.Shows', $showsField);
    return $fields;
    }

    }

    class Whatson_Controller extends Page_Controller {

    }
    ?>

    Show.php

    <?php

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    class Show extends DataObject {

    private static $db = array(
    'ID' => 'Int',
    'Name' => 'Varchar',
    );

    private static $has_one = array(
    'Whatson' => 'Whatson'
    );

    function getInfo() {
    return $this->renderWith('Show');
    }

    }
    ?>

    Shows.ss

    Hello we are here!

    No matter what I do, rebuild. flush I cannot get the Shows.ss file to read, it's in the layout folder!

    What am I doing wrong?

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: More template woes Link to this post

    From where/how are either of the two getInfo() functions called? I suppose from within a template? In that case we'd need to see that template before we can really answer your question.

    Second thing: in the Layout section you'd normally place templates that are to be loaded by the $Layout placeholder, if you have that in your main page template. SilverStripe will look there for a template named after the current Page type.

    Includes is meant for bits of templates that are loaded into another template by the <% include ... %> statement.

    Basically you can place other templates anywhere in any homemade directory under the templates section, but you might have to use ?flush=all (not ?flush=1) for SilverStripe to find them.

    309 Views
Page: 1
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.