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.


Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Adding a PayPal donate button

Go to End

12 Posts   4908 Views


14 August 2007 at 4:52pm Community Member, 6 Posts

I am about to pull my hair out! I see that SilverStripe's site has a donation page with a PayPal button, but mine isn't working. In fact, any code I put into the HTML thingy in the editor (I can only assume that's the only way to input HTML the way I want it?) chews it up and spits it out, not rendering anything right. What am I doing wrong?

I input my donate button code into the page content, through the HTML popup.
I update.
I save/publish.

The code is mangled on the site. It attempts to show the PayPal button, to no avail. A view-source reveals that the rest of the code has been more or less erased.

I'm not too fond of the WYSIWYG editor, but could over-look it.... But as a not-for-profit, my site needs it's donate button! I need to be able to paste in code on my site as *I* want it to be... Does SilverStripe not allow that??

Thanks for any help!


14 August 2007 at 5:14pm Forum Moderator, 5511 Posts

Your might have to create a Donate Page type and then hard code the paypal donate link into the template. Have a read of the second tutorial on how to create a page type a brief one for you might be like

- mysite/code/DonatePage.php

class DonatePage extends Page {
class DonatePage_Controller extends Page_Controller {

- mysite/templates/layout/

// all the normal stuff
// all custom Donate HTML Stuff

Then do a db/build. Refresh the CMS and make sure the Donate Page is of Page type - DonatePage.

Like I said, the second tut will probably provide better information


14 August 2007 at 5:22pm Community Member, 6 Posts

I hadn't even thought of that... I will do that. Thanks so much, willr!


14 August 2007 at 5:31pm (Last edited: 14 August 2007 5:37pm), Forum Moderator, 921 Posts

Alternatively, you can do this:

In Page_Controller class, add this:

function Content() {
return str_replace('$PayPalForm', $this->PayPalForm(), $this->Content);

function PayPalForm() {
return 'replace me with paypal form html here!';

These two functions allow you to enter $Paypal anywhere in the content editors within the CMS. It gives more flexibility instead of being dumped directly into the templates, if for example, you wanted the paypal button to come between 2 paragraphs of content.

It just string replaces $Paypal with the HTML of the PayPal html. It works for anything really, including adverts if you wanted to throw them straight into the content (separate from the templates). Ideally it's good for little 'snippets' of external html or javascript.

$PayPalForm can be called in the templates, as well as in the content editor (WYSIYWG editor in the SS CMS).

Hope this helps!



14 August 2007 at 5:36pm Community Member, 6 Posts

I think I like that even more - So I can include the button in multiple places within the site. Thanks, Sean!


14 August 2007 at 5:40pm (Last edited: 14 August 2007 5:43pm), Forum Moderator, 921 Posts

It's a more ideal solution as it works in both the templates and the CMS Content field (the rendered results of $Content. :-)

There's also less overhead of not having to create another class (which creates db tables, etc).



14 August 2007 at 6:45pm Forum Moderator, 5511 Posts

man we need a page on doc with that stuff, when the hell could we do that ?!? thats awesome never even thought that was even possible! maybe I just never thought about it.. So i'm guessing that we can overload everything else like that Titles etc then sean?


14 August 2007 at 6:49pm (Last edited: 14 August 2007 6:55pm), Forum Moderator, 921 Posts

We can do that indeed. It is in the wiki, but it's sort of hidden.

Check it out. It's there. Thanks to Sam for documenting this one, and coming up with the idea!

The simple things are always the most effective. It's just a string replace for the Content field to add some HTML in wherever it's found!

It's generally good when you can do function Title() {} to achieve $Title in the templates where your class doesn't inherit SiteTree functions - for example, if you're creating a class that extends DataObject like an article category or something.



Go to Top