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

Add a shortcode to Page class through an extension?


Go to End


3 Posts   904 Views

Avatar
Pix

Community Member, 158 Posts

29 December 2016 at 8:54am

Is it possible to add a shortcode to Page class through an extension? So far, my shortcodes are not getting parsed or registered. In my module's _config.php I have:

Page::add_extension('MyPageExtension');
ShortcodeParser::get('default')->register('test_shortcode', array('Page', 'TestShortcode'));

and the extension looks like this:

<?php
class MyPageExtension extends DataExtension {

public function TestShortcode($arguments, $content = null, $parser = null, $tagName) {
.......

no worky :-(

Avatar
WebSpilka

Community Member, 89 Posts

9 January 2017 at 7:16am

Avatar
martimiz

Forum Moderator, 1391 Posts

10 January 2017 at 9:06am

Edited: 10/01/2017 9:06am

The shortcode handler test_shortcode() should be a static function, and as such it could live in any class...

https://docs.silverstripe.org/en/3/developer_guides/extending/shortcodes/#defining-custom-shortcodes