View more context



From a static shortcode handler function, is it possible to access the Request to access the url Or just, is it possible to get the current url from a static context? Using \SilverStripe\Control\HTTPRequest::getURL() and $this->getRequest()->getURL() work only in instance context


Controller::curr()->getRequest() ?

👍 (1)

Controller::curr()->getRequest() works, thanks @guttmann. Will do the check, thanks for the tip, @MichalKleiner

Matt Lang

Is there a way I can make sure I get a link without ?stage=stage? I’m using $myModel->MyRelatedPages()->first()->Link(). What I want is just the normal link to the latest published version of that page, not with stage=stage appended.

Matt Lang

Elsewhere I’ve gotten around this with Versioned::get_by_stage('MyPage', Versioned::LIVE)->byID($id)->Link() But because it’s a many_many relation I don’t easily have the ID of the related model. It’d be nice if there were something available like $myModel->MyRelatedPages()->first()->latestPublishedVersion()->Link()


I asked myself this a few times and ended up with something like:

  1. $pharsedURL = parse_url(...);
  2. $url = $pharsedURL['scheme'] .'://'. pharsedURL['host'] . $pharsedURL['path'];