5

In the Silverstripe templating syntax $AbsoluteLink returns the full URL of a page/object, including the protocol and host:

http://www.example.com/event/ics

I want to be able to call a full URL with a different protocol:

webcal://www.example.com/event/ics

What is the best way to achieve this?

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
BaronGrivet
  • 4,364
  • 5
  • 37
  • 52

2 Answers2

5

Make a new getter function on your page:

public function WebcalLink() {
    $absolute = $this->AbsoluteLink();
    $webcal = str_replace(Director::protocol(), "webcal://", $absolute);
    return $webcal;
}

You can call it from your template using $WebcalLink

cryptopay
  • 1,084
  • 6
  • 7
5

Define a custom link method that replaces the current website protocol with your desired one. ie.

public function WebCalLink()
{
    return str_replace(Director::protocol(), 'webcal://', Director::protocolAndHost()) . $this->Link();
}
scrowler
  • 24,273
  • 9
  • 60
  • 92
LiveSource
  • 6,230
  • 4
  • 21
  • 20