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.

Archive /

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
Reply


12 Posts   5015 Views

Avatar
Kimberlymarie

Community Member, 6 Posts

14 August 2007 at 4:52pm

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!

Avatar
Willr

Forum Moderator, 5513 Posts

14 August 2007 at 5:14pm

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/DonatePage.ss

// all the normal page.ss 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

Avatar
Kimberlymarie

Community Member, 6 Posts

14 August 2007 at 5:22pm

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

Avatar
Sean

Forum Moderator, 922 Posts

14 August 2007 at 5:31pm

Edited: 14/08/2007 5:37pm

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!

Sean

Avatar
Kimberlymarie

Community Member, 6 Posts

14 August 2007 at 5:36pm

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

Avatar
Sean

Forum Moderator, 922 Posts

14 August 2007 at 5:40pm

Edited: 14/08/2007 5:43pm

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).

Sean

Avatar
Willr

Forum Moderator, 5513 Posts

14 August 2007 at 6:45pm

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?

Avatar
Sean

Forum Moderator, 922 Posts

14 August 2007 at 6:49pm

Edited: 14/08/2007 6:55pm

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

http://doc.silverstripe.com/doku.php?id=customising-content-in-your-templates

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.

:-)

Sean

Go to Top