Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Tutorial 2 SS is not using the currect templates?

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: 1272 Views
  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Tutorial 2 SS is not using the currect templates? Link to this post

    Hi all,

    I am attempting to go through Tutorial 2 of SS
    http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site

    Now I've got all the .ss and .php pages setup.

    mysite\code\ArticleHolder.php
    mysite\code\ArticlePage.php
    mysite\code\HomePage.php

    themes\tutorials\templates\Layouts\ArticleHolder.ss
    themes\tutorials\templates\Layouts\ArticlePage.ss
    themes\tutorials\templates\Layouts\HomePage.ss

    Have done the dev flush, flush all etc
    I can create a Article, Holder, Article Page or Homepage in the admin and under behaviour page type it will show whatever I have selected.
    But back on the front end none of these templates appear to be being used.

    I debug by going:
    ?showtemplate=1

    and it always shows
    themes.tutorial.templates.Page.ss

    So my created templates aren't actually being used on the front end.

    Heres my class files also:

    mysite\code\ArticleHolder.php
    <?php
    /**
    * Defines the ArticleHolder page type
    */
    class ArticleHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );

    static $allowed_children = array('ArticlePage');
    }

    class ArticleHolder_Controller extends Page_Controller {

    }

    ?>

    mysite\code\ArticlePage.php
    <?php
    class ArticlePage extends Page {

    static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );

    static $icon = "themes/tutorial/images/treeicons/news";

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

    return $fields;

    }
    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

    mysite\code\HomePage.php
    <?php
    /**
    * Defines the HomePage page type
    */

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

    static $icon = "themes/tutorial/images/treeicons/home";

    }

    class HomePage_Controller extends Page_Controller {

    function LatestNews($num=5) {
    $news = DataObject::get_one("ArticleHolder");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }

    }

    ?>

    Any help would be great

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Note your Layouts folder should be called 'Layout'

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Hi Will

    Sorry that was a typo the directory structure is indeed

    themes\tutorial\templates\Layout

    Any other ideas?

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Make sure you have done a ?flush=1 and your Page.ss contains a $Layout variable for getting the subtemplates in the layout folder.

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Will I think $Layout might be my problem.

    Where should that sit in the Page.ss file?

    Here's my Page.ss

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
       <head>
          <% base_tag %>
          $MetaTags
          <link rel="stylesheet" type="text/css" href="tutorial/css/layout.css" />
          <link rel="stylesheet" type="text/css" href="tutorial/css/typography.css" />
          <link rel="stylesheet" type="text/css" href="tutorial/css/form.css" />
       </head>
       <body>
          <div id="Main">
          <ul id="Menu1">
    <% control Menu(1) %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
    <% end_control %>
    </ul>

             <div id="Header">
                <h1>$Title</h1>
             </div>
             <div id="ContentContainer">
    <% if Menu(2) %>
    <ul id="Menu2">
    <% control Menu(2) %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <% end_if %>

                <div id="Content" class="typography">
                
    <% if Level(2) %>
    <div class="breadcrumbs">
    $Breadcrumbs
    </div>
    <% end_if %>
                
                   $Content
                   $Form
                </div>
             </div>
             
             <div class="newsDetails">
    Posted on $Date.Nice by $Author
    </div>
    $PageComments
             
             <div id="Footer">
                <span>This is PAGE.SS Visit <a href="http://www.silverstripe.com" title="Visit www.silverstripe.com">www.silverstripe.com</a>; to download the CMS
                
                
                <table width="175" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>

    </span>
             </div>
          </div>
          $SilverStripeNavigator

       </body>
    </html>

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Okay I found out why the template werent loading and that was because of my not reading the subtemplate section of tutorial 1.

    Now that I have that all worked out, my templates load however on the Article Holder summary I just get nothing showing its blank.

    Do I have to load the Article Pages in a specific way??? I have 5 top level Article Pages there, but as I said they arent shown in the Articel Holder page.

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Tutorial 2 SS is not using the currect templates? Link to this post

    Don't worry Will got it all worked out and I am now cooking with gas. (I had to load the Article Pages underneath the Article Holder, not at the top level.)

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