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.

Template Questions /

Control based upon conditional operator


2 Posts   1876 Views


Community Member, 19 Posts

22 December 2009 at 9:34am

Within my template, I'm trying to loop display individual Links organized by their respective LinkCategories. Do I have my model set up completely wrong to achieve this? As it is, I can't get the template to output any data.


class LinkHolder extends Page {
static $singular_name = 'LinkHolder';
static $plural_name = 'LinkHolders';
static $has_many = array(
'Links' => 'Link'
function getCMSFields() {
$fields = parent::getCMSFields();
$misAmigosTable = new ComplexTableField($this, 'Links', 'Link');
$fields->addFieldToTab('Root.Content.Mis Amigos', $misAmigosTable);
return $fields;
class LinkHolder_Controller extends Page_Controller {}


class Link extends DataObject {
static $singular_name = 'Link';
static $plural_name = 'Links';
static $db = array(
'LinkURI' => 'Text',
'LinkDisplay' => 'Text',
'LinkCategory' => 'Varchar(100)'
static $has_one = array(
'LinkHolder' => 'LinkHolder'
function getCMSFields() {
$categories = array(
'MisAmigos' => 'Mis Amigos'
$fields = new FieldSet(
new TextField('LinkURI', 'Link URI'),
new TextField('LinkDisplay', 'Link Display Text'),
new DropdownField('LinkCategory', 'Link Category', $categories)
return $fields;

<% if Links %>
<% if LinkCategory == MisAmigos %>
<ul id="mis-amigos" class="links">
<% control Links %>
<li><a href="$LinkURI">$LinkDisplay</a></li>
<% end_control %>
<% end_if %>
<% end_if %>


Community Member, 105 Posts

14 January 2010 at 8:03pm

I would do this in the LinkHolder_Controller by making a custom methods

Change Category to has_one relationship

Create LinkCategory to extend DataObject have a look at ModelAdmin to manage your links

create functions to retrieve categories and links
control the functions you created and output in the desired way

Sorry I couln't provide any code at the moment as I was suppose to leave work 30misn ago let me know if you need a better explaination.