I've been digging around and haven't found an existing Twig filter for what I'm trying to do. Basically, I'd like a filter that would provide a hash of a phrase.

Pseudo-template code would be something like this:

{{ "my phrase here"|hashwithmd5 }} 

And would generate this in my rendered template:


Does something like this exist? Am I going about this in a bad way?


sounds like a simple plugin will do the trick for you. You will need to set up your main plugin class and a variable class.

Your variable class will look something like this:

namespace Craft;

class YourPluginNameVariable
    public function makeHash($string)
        $hashed = md5($string);
        return $hashed;

You can call this in your templates like this:

{{craft.yourpluginname.makeHash('my phrase here')}}

Hope this helps!

| improve this answer | |
  • That's what I thought I might need to do. Just didn't want to reinvent the wheel if I didn't need to. Thank you! – John Morton Feb 14 '15 at 19:05
  • 1
    I wrote one quickly and have posted it to my GitHub page: github.com/johnfmorton/Craft-MD5-Twig-Filter-Plugin You use it like {{ "my phrase here" | toMd5 }} – John Morton Feb 14 '15 at 19:45
  • Nice! Seems a cleaner than using the variable route in my answer. – Aaron Berkowitz Feb 14 '15 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.