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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

More template woes


Go to End


2 Posts   1014 Views

Avatar
alana

Community Member, 7 Posts

4 March 2014 at 5:04am

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?

Avatar
martimiz

Forum Moderator, 1391 Posts

4 March 2014 at 11:03pm

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.