Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Do I need to re-design my page structure?

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

Page: 1
Go to End
Author Topic: 1325 Views
  • ianpiper
    Avatar
    Community Member
    32 Posts

    Do I need to re-design my page structure? Link to this post

    Hi,

    I'd appreciate some advice about a site I am building. I thought I had the right approach but I'm beginning to doubt it.

    The site needs to show content arranged in blocks within 3 columns across the page. In any column there may be one or more blocks. My approach was to create a page type called a tlColumnHolder as a container for columns. A tlColumnHolder contains three columns (the class name for these is ContentBlockHolder). Each ContentBlockHolder contains one or more ContentBlockPages (the real content). The attached png file shows a screenshot as it currently stands. The code in the tlColumnHolder.ss file is shown below.

    I'm now running into problems with things like site maps and individual page display, and I have a feeling that I have overcomplicated the structure. I actually started with just ContentBlockHolder and ContentBlockPage, but couldn't work out how to group all of the ContentBlockPage objects for a given column together.

    I expect I can hack my way through this in its current form, but I can't help thinking that I'm missing a simpler way to achieve what I want to do. Can anyone give some constructive criticism of my approach?

    Thanks for any advice,

    Ian.
    --

    ==== tlColumnHolder ====
    <div id="Content" class="typography">      
    $Content
    <div id="ColumnList">
    <% control Children %>
             <div id="$ColumnRef">
                <% control Children %>
                   <div class="articleHeader">
                      <p class="$BlockColour">$Title</p>
                   </div>
                   <div class="cbb">
                      <p>$Content.FirstParagraph <br />
                      <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></p>
                      <p>[Block information: column is <% control Parent %>$ColumnRef<% end_control %>, row is $RowNumber and block colour is $BlockColour]</p>
                   </div>
                <% end_control %>
             </div>
    <% end_control %>
    </div>
    </div>
    ==== tlColumnHolder ====

    Attached Files
  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: Do I need to re-design my page structure? Link to this post

    I meant to add, I wondered whether it is possible to build conditional logic into templates, so that I could have something like (pseudo-code, of course):

    <div id="ColumnList">
    <% control Children %>
             <div id="columnLeft">
                <% control Children where $ColumnRef="columnLeft" %>
                   [ContentBlockPages for left column]
                <% end_control %>
             </div>
             <div id="columnMiddle">
    [and so on]

                

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Do I need to re-design my page structure? Link to this post

    Hi Ian,

    The logic belongs in your PHP file, not your template.

    Add the following method to your Page class in Page.php:

    function LeftChildren() {
    if($this->ID) {
    return DataObject::get("SiteTree", "ParentID = " . $this->ID . " AND ColumnRef = 'columnLeft'");
    }
    }

    Then you can put <% control LeftChildren %> into your template.

    If you have more than one column, you could also do it this way.

    function ChildColumn($column) {
    if($this->ID) {
    $SQL_column Convert::raw2sql($column);
    return DataObject::get("SiteTree", "ParentID = " . $this->ID . " AND ColumnRef = '$SQL_column'");
    }
    }

    Then you can put <% control ChildColumn(columnLeft) %> into your template.

  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: Do I need to re-design my page structure? Link to this post

    Thanks Sam, that solved the problem.

    Ian
    --

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