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.

Template Questions /

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

Do I need to re-design my page structure?


Go to End


4 Posts   2903 Views

Avatar
ianpiper

Community Member, 32 Posts

15 March 2009 at 10:23am

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
Avatar
ianpiper

Community Member, 32 Posts

15 March 2009 at 10:35am

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]

Avatar
Sam

Administrator, 690 Posts

15 March 2009 at 1:57pm

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.

Avatar
ianpiper

Community Member, 32 Posts

24 March 2009 at 4:51am

Thanks Sam, that solved the problem.

Ian
--