Skip to content

Instantly share code, notes, and snippets.

@Ethanhackett
Last active August 29, 2015 14:17
Show Gist options
  • Save Ethanhackett/943de9232d8cfd5d3db5 to your computer and use it in GitHub Desktop.
Save Ethanhackett/943de9232d8cfd5d3db5 to your computer and use it in GitHub Desktop.
---
layout: default.hbs
url: '?utm_source=Source&utm_medium=Medium&utm_term=Term&utm_content=Content&utm_campaign=Name'
---
{{> global-header }}
<a href="http://www.domain.com/{{url}}">Click Me</a>
or
{{> partial-with-anchor }}
{{> global-footer }}
@Ethanhackett
Copy link
Author

I've tried different output methods
{{{url}}}
{{url}}
{{& url}}

I've also tried escaping, using single and double quotes along with > and | YAML formatting.

@doowb
Copy link

doowb commented Mar 20, 2015

Are you using something after assemble in your build process? When I use {{{url}}} it doesn't escape the &.

@jonschlinkert
Copy link

@Ethanhackett, try using this just to see if it's a handlebars escaping issue:

module.exports.register = function (Handlebars, options)  { 
  Handlebars.registerHelper('url', function (str)  { 
    return new Handlebars.SafeString(str);
  });
};

Keep in mind that if you call the helper inside a block (e.g. {{#foo}} {{url url}} {{/foo}}, you will need to tell handlebars that you want the same scope as the "parent" block, so in the url helper you would do {{url ../url}} to go up a level. Hope that makes sense.

(you can stop there, but in case you're curious, by default handlebars tries to prevent unsafe code from rendering without your knowledge, which is probably the cause of the issue you're having - technically it's a good thing. SafeString is how you tell handlebars that you don't want its protection)

@jonschlinkert
Copy link

that's a good question @doowb, might make this easier to solve if it is

@Ethanhackett
Copy link
Author

@doowb yeah if I strip out some of the other processes it looks correct with {{{url}}} and {{& url}}. I think it's grunt-inline-css that's messing with the ampersands...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment