Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Adding a PayPal donate button

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

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

Page: 1 2
Go to End
Author Topic: 4888 Views
  • Kimberlymarie
    Avatar
    Community Member
    6 Posts

    Adding a PayPal donate button Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Adding a PayPal donate button Link to this post

    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

  • Kimberlymarie
    Avatar
    Community Member
    6 Posts

    Re: Adding a PayPal donate button Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Adding a PayPal donate button Link to this post

    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

  • Kimberlymarie
    Avatar
    Community Member
    6 Posts

    Re: Adding a PayPal donate button Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Adding a PayPal donate button Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Adding a PayPal donate button Link to this post

    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?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Adding a PayPal donate button Link to this post

    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

    4888 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.