Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

shortcodehandler displaying page variables


Go to End


4 Posts   2087 Views

Avatar
Borto

Community Member, 2 Posts

25 September 2010 at 2:48am

In order to make it possible to display some module-output in the middle of a $Content-block I have successfuly created a shortcodehandler.

The shortcodehandler displays the dataobjects like we expected, execpt for one thing. We would like to use the page variables of the page on which the shortcode is called.

We would like to use $URLSegment and display the pagetitle in the shortcode template. Is this possible in some way? Because the shortcodehandler is not defined in the page controller the $this-variable is not available.

Avatar
Martijn

Community Member, 271 Posts

25 September 2010 at 7:50pm

I think Controller::curr() is what you need.

if($c = Controller::curr()){
  $currentPageID = $c->ID;
}

Avatar
Borto

Community Member, 2 Posts

25 September 2010 at 11:38pm

Thanks, just what I needed.

Problem solved.

Avatar
LinseyM

Community Member, 99 Posts

9 April 2013 at 1:06am

Hi there, I posted this up on SSBits too, but just in case...

Can anyone help me with how to use "Controller::curr()", as mentioned in the SSBits tutorial please? http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/

I've got "ClientYouTubeID" as a page variable, rather than as part of the ShortCode, so I need to be able to call the variable $ClientYouTubeID within my YouTube.ss template, and I don't understand how to do it. At the moment it just doesn't return anything.

Thanks!