almonk Posted June 2, 2011 Share Posted June 2, 2011 Hi guys, Made this very simple module to add Facebook like buttons to pages, posts, whatever you fancy. Find the public gist here: https://gist.github.com/1004219 Once you've installed the module, it's very easy to use in your templates: <div class="page"> <h1><?=$page->title?></h1> <h3><?=$page->created?></h3> <?=$page->body?> <? $like = $modules->get('FacebookLike'); $like->url = $page->url; $like->render(); ?> </div> Easy. There's a huge amount of room for improvement, but I thought it'd be worth sharing. Cheers, Al Link to comment Share on other sites More sharing options...
ryan Posted June 2, 2011 Share Posted June 2, 2011 Looks good! Thanks for putting this together and sharing it here. I have two minor suggestions: Make is so that setting the page URL is optional, and it defaults to the current page if you don't set it. Have your render() function return the value rather than echoing it directly. One of the concepts with PW is that nothing sends any output, except your template. This is just for practical reasons, since PW templates can be used as controllers to populate other templates/views/includes, etc. That way your template can decide whether to echo or store the result for later output. public function ___render() { if(!$this->url) $this->url = $this->page->url; return '<iframe src="http://www.facebook.com/plugins/like.php?href='.$this->url.'&layout='.$this->layout.'&show_faces='.$this->showFaces.'&width='.$this->width.'&action=like&font='.$this->font.'&colorscheme=light&height='.$this->height.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$this->width.'px; height:'.$this->height.'px;" allowtransparency="true"></iframe>'; } With the above change, you could decide to skip the URL setting part, and you'd have to echo or store the output: echo $modules->get('FacebookLike')->render(); What's funny is that I just had a client ask for a like button, so your new module arrived at the perfect time and I will definitely use it. Thanks! Link to comment Share on other sites More sharing options...
almonk Posted June 2, 2011 Author Share Posted June 2, 2011 Great ideas Ryan, I've still got a lot to learn with module development I've updated the gist with your input. Link to comment Share on other sites More sharing options...
almonk Posted June 2, 2011 Author Share Posted June 2, 2011 Also, Ryan, if you make any amends of additions to the code while using it, please fork my gist so everyone can have the latest updates Link to comment Share on other sites More sharing options...
ryan Posted June 2, 2011 Share Posted June 2, 2011 Almonk, thanks for the updates. If I make any changes to the module, I'll be sure to fork. Regarding modules, it looks to me like you've got a pretty good handle on it. But once I get through the 2.1/2.2 updates I'm going to write a full module guide, as this is currently not well covered in the online documentation (other than lots of examples in the forums). Thanks, Ryan Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now