Nov
How to write a simple Liquid filter for Mephisto
When I first started customizing the scribbish theme for the site, I wanted links in the ‘meta’ section to submit the current article to social bookmarking sites like del.icio.us and digg. Hey, everyone else does it, right? I did a little digging and wound up with the following:
<a href="http://del.icio.us/post?url=http://www.benlog.org/{{ article.url }}&title={{ article.title }}">del.icio.us</a>
<a href="http://www.digg.com/submit?phase=2&http://www.benlog.org{{ article.url }}&title={{ article.title}}">digg this</a>
Pretty simple feat, sure, but it’s just not doing it for me. Who wants these hacked up urls polluting their template code? Who knows, I might want to re-use these links elsewhere, so it couldn’t hurt if they were a little simpler, say, done via a Liquid filter. What if we could write this instead?
{ article | link_to_delicious }
{ article | link_to_digg : 'digg this' }
Wow, that’s much easier on the eyes. Okay, so that’s what I want, now how do I pull it off? I thought this would be the perfect opportunity to learn how to write custom Liquid filters for Mephisto, and share it with you guys.
