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.

Template Questions /

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

Basic Extending


Go to End


2 Posts   2137 Views

Avatar
Richie

Community Member, 18 Posts

22 December 2008 at 10:03pm

Edited: 22/12/2008 10:04pm

Hi, I want to extend a class and found this example: http://doc.silverstripe.com/doku.php?id=recipes:adding_metatags. This works as expected so I use the same approach on the PageCommentInterface class. My code:

==mysite/code/CustomCommentInterface.php==
class CustomCommentInterface extends DataObjectDecorator {
	function CustomCommentForm() {
		return 'Foo';
	}
}

==mysite/_config.php==
DataObject::add_extension('PageCommentInterface', 'CustomCommentInterface.php');

==mysite/templates/Layout/ArticlePage.ss==
$CustomCommentForm ('Foo' is not showing up!?)

Thanks for your time!

Note. I asked this before but the old forum is archived. I got a reply from howardgrigg (thanks for that!) but I don't want to alter the core.

Avatar
dio5

Community Member, 501 Posts

27 December 2008 at 10:49pm

Hi,

instead of using a dod for that, I would extend PageCommentInterface directly.

You'll see that this is called in ContentController.php (around line 300). - see the method 'PageComments'.

In your Page_Controller you could then do more or less the same:

function CustomComments() {
		if($this->data() && $this->data()->ProvideComments) {
			return new CustomCommentInterface($this, 'CustomComments', $this->data());
		} else {
			if(isset($_REQUEST['executeForm']) && $_REQUEST['executeForm'] == 'CustomComments.PostCommentForm') {
				echo "Comments have been disabled for this page";
				die();
			}
		}
	}

which gives you the $CustomComments tag in yr template...

Hope this might help a bit.