Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Page Links in DOM

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 843 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    [SOLVED] Page Links in DOM Link to this post

    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??

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Page Links in DOM Link to this post

    "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

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: [SOLVED] Page Links in DOM Link to this post

    Hi, thanks, I've renamed Link to PageLink, and $PageLink.Link works as it should.

    Cheers
    Nick

    843 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.