7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED] Page Links in DOM
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 763 Views |
-
[SOLVED] Page Links in DOM

28 July 2009 at 10:23am Last edited: 28 July 2009 11:08am
Hi, I'm trying to output images in a sidebar which link to other pages in the site. I've got it working fine, but just cannot get the page links to output. I'm sure it's something easy I'm overlooking....hopefully someone else can spot it ....
LinkImageItem.php
class LinkImageItem extends DataObject
{
static $db = array (
'Caption' => 'Text'
);
static $has_one = array (
'LinkImage' => 'Image',
'Page' => 'Page',
'Link' => 'SiteTree'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Caption','Caption'),
new SimpleTreeDropdownField("LinkID", "Select a page to link to", "SiteTree"),
new ImageField('LinkImage','Link Image')
);
}
}Page.php
class Page extends SiteTree {
public static $db = array();
public static $has_one = array();
public static $has_many = array(
'ResourceFile' => 'File',
'LinkImageItems' => 'LinkImageItem'
);
static $icon = "themes/smartpack/images/treeicons/page";
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldsToTab("Root.Content.ResourceFiles", new AssetManager($this,"ResourceFiles","ResourceFile"));
// setup the page link images
$manager = new ImageDataObjectManager(
$this, // Controller
'LinkImageItems', // Source name
'LinkImageItem', // Source class
'LinkImage', // File name on DataObject
array('Name' => 'Name'),
'getCMSFields_forPopup' );
$f->addFieldToTab("Root.Content.LinkItems",$manager);
return $f;
}
}In Page.ss
<% control LinkImageItems %>
$LinkImage
<a href="$Link">$Caption</a><% end_control %>
Tried all sorts of different ways in the template, but the link never outputs (everything else does)
any ideas??
-
Re: [SOLVED] Page Links in DOM

28 July 2009 at 10:43am
"Link" is a really bad choice of a fieldname because it is a function on SiteTree objects. But assuming that's not an issue, you have $Link returning a SiteTree object, so the correct code would be $Link.Link
-
Re: [SOLVED] Page Links in DOM

28 July 2009 at 11:07am
Hi, thanks, I've renamed Link to PageLink, and $PageLink.Link works as it should.
Cheers
Nick
| 763 Views | ||
|
Page:
1
|
Go to Top |
