Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcode does not render HTML #460

Closed
mathiasha opened this issue Mar 22, 2019 · 4 comments
Closed

Shortcode does not render HTML #460

mathiasha opened this issue Mar 22, 2019 · 4 comments
Labels
common-pitfall-eligible Might need to be listed on the common problems docs page education: template language Learning about a template language.

Comments

@mathiasha
Copy link

mathiasha commented Mar 22, 2019

In my eleventy config I have this shortcode:

module.exports = function(eleventyConfig) {
  eleventyConfig.addShortcode("testCode", function(name) {
    return `<div class="some-class">${name}</div>`;
  });
}

In my handlebars file I have this
{{ testCode 'Mathias' }}

But the shortcode is being rendered as a string. So in the browser it looks like this

<div class="some-class">Mathias</div>

Am I doing something wrong?

@corderophi678
Copy link

It looks like you might be escaping the backticks in your return statement? Might that be the cause?

@zachleat
Copy link
Member

This is a good question! Handlebars escapes shortcodes by default so you want the triple-stash for unescaped output {{{ testCode 'Mathias' }}}.

@zachleat
Copy link
Member

I will update the documention for shortcodes to make this clearer.

@zachleat zachleat added education: template language Learning about a template language. common-pitfall-eligible Might need to be listed on the common problems docs page labels Mar 22, 2019
zachleat added a commit that referenced this issue Mar 22, 2019
zachleat added a commit to 11ty/11ty-website that referenced this issue Mar 23, 2019
zachleat added a commit that referenced this issue Mar 23, 2019
zachleat added a commit to 11ty/11ty-website that referenced this issue Mar 23, 2019
@zachleat
Copy link
Member

Both https://www.11ty.io/docs/languages/handlebars/ and https://www.11ty.io/docs/shortcodes/ have been updated with this information.

Thanks for filing this! Very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common-pitfall-eligible Might need to be listed on the common problems docs page education: template language Learning about a template language.
Projects
None yet
Development

No branches or pull requests

3 participants