3215 Posts in 848 Topics by 811 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1636 Views |
-
Control based upon conditional operator

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.
LinkHolder.php
<?php
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 {}
?>Link.php
<?php
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;
}
}
?>LinkHolder.ss
<% if Links %>
<% if LinkCategory == MisAmigos %>
<ul id="mis-amigos" class="links">
<h5>$LinkCategory</h5>
<% control Links %>
<li><a href="$LinkURI">$LinkDisplay</a></li>
<% end_control %>
</ul>
<% end_if %>
<% end_if %> -
Re: Control based upon conditional operator

14 January 2010 at 8:03pm
I would do this in the LinkHolder_Controller by making a custom methods
Links.php
Change Category to has_one relationshipCreate LinkCategory to extend DataObject have a look at ModelAdmin to manage your links
LinkHolder_Controller.php
create functions to retrieve categories and linksLinkHolder.ss
control the functions you created and output in the desired waySorry 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.
| 1636 Views | ||
|
Page:
1
|
Go to Top |


