3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1190 Views |
-
Do I need to re-design my page structure?

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 "{$Title}"">Read more >></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 ==== -
Re: Do I need to re-design my page structure?

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] -
Re: Do I need to re-design my page structure?

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.
-
Re: Do I need to re-design my page structure?

24 March 2009 at 4:51am
Thanks Sam, that solved the problem.
Ian
--
| 1190 Views | ||
|
Page:
1
|
Go to Top |


