Jump to:

21286 Posts in 5733 Topics by 2602 members

General Questions

SilverStripe Forums » General Questions » Choosing a URL from sitetree

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3 4
Go to End
Author Topic: 4658 Views
  • reececropley
    Avatar
    Community Member
    11 Posts

    Re: Choosing a URL from sitetree Link to this post

    Hey,

    Im using the SiteTree to allow the user to choose a page on the site to create a link.

    The Page.php has this code

    public static $has_one = array(
          
          "CaptionOneLink" => "SiteTree"
       );

    public function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.SliderText", new TreeDropdownField('CaptionOneLink', 'Caption 1 Link', 'SiteTree'));
    return $fields;
    }

    The template file page.ss has the following:

    <a href="$CaptionOneLink.Link">Link to page</a>

    In the admin section I can see the dropdown, with the pages in their. However when I select one and save it display "(Choose One)" rather than the selected page name.

    When I load the page there is no link in the <a> anchor tag. I checked the database and the ID it has entered for CaptionOneLink is 0.

    Is there something I'm missing? Or Documentation you can link to?

  • marc79
    Avatar
    Community Member
    55 Posts

    Re: Choosing a URL from sitetree Link to this post

    Hi,

    I have been able to add a SiteTree dropdown to my DataObject pop up however I only want to show specific page types.

    Is it possible to filter the pages displayed in the dropdown based on $ClassName?

    This is what I have so far:

    $fields->push( new TreeDropdownField('PackageType','Package Page', 'SiteTree', 'ID'));

    There are many different packages available and these are split up into various types of packages which I want to be displayed on the pages of the site. Because packages can only be displayed on pages with a $ClassName of 'PackagePage' these are the only pages I want to display in the dropdown, make it easier for my client.

    Any help greatly appreciated.

    thanks

    4658 Views
Page: 1 2 3 4
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.