Jump to:

23358 Posts in 18005 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Outputting URL value in template

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

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

Page: 1
Go to End
Author Topic: 259 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    Outputting URL value in template Link to this post

    Probably a very simple one......

    I have a dataobject which is returning a calendar page

    public function calendar($request) {
          $page = DataObject::get('SiteTree','"SiteTree"."ID" =' . $this->ID);
          return $this->customise(array("resort"=>$page))->renderwith(array('CalendarPage','Page'));
       }

    I am linking to the calendar as such:

    /[region-name]/[resort-name]/calendar/55

    Where 55 (in this case) is the ID of a product relating to a resort. I need to get this value (in this case 55) into the data-id of a div in my calendar template as my jQuery calendar uses this to fetch some jSON to display events on a calendar.

    How can I do this?

    Thanks

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: Outputting URL value in template Link to this post

    Got it.

    public function calendar($request) {
          //$productID = Director::urlParam('id');
          //$productID = 'adfasdf';
          $page = DataObject::get('SiteTree','"SiteTree"."ID" =' . $this->ID);
          return $this->customise(array("resort"=>$page))->renderwith(array('CalendarPage','Page'));
       }
       
       public function ProductID(){
          $URLParams = Director::URLParams();
       $Action = $URLParams['OtherID'];
          return($Action);
       }

    and then call it in the template with $ProductID

    Is this the correct way of doing this or is there a more efficient way?

    259 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.