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

Meta tag interpolation issue #2768

Closed
tony99nyr opened this issue Apr 4, 2017 · 6 comments
Closed

Meta tag interpolation issue #2768

tony99nyr opened this issue Apr 4, 2017 · 6 comments

Comments

@tony99nyr
Copy link

I have found that meta tags don't interpolate the same way that title, div and other tags do. Leaving the meta!= metaTagTest line apparently is invalid syntax and will bring me to my error page. The title is totally fine though and the tag is replaced correctly. I expect both tags to behave the same way, but they do not.

res.render('index', {
  metaTagTest: '<meta data-react-helmet="true" property="og:title" content="My app"/>',
  title: '<title data-react-helmet="true">My App</title>'
});

html
  head
    meta!= metaTagTest
    title!= title
  body
@ForbesLindesay
Copy link
Member

You're nesting the tags here, which isn't what you meant to do. Browsers often do odd thing when you nest tags that aren't meant to be nested.

@tony99nyr
Copy link
Author

Other tags seem to handle this just fine i.e. the title. If you don't think its a bug I would still like you to solve the problem.

For the record, given the following string <meta data-react-helmet="true" property="og:title" content="My app"/>' how would you render this out within a pug template to become a valid html meta tag?

@tony99nyr
Copy link
Author

By the way, it's not a one-off question. We are using react-helmet to manage our open graph tags. In our server side rendering we get the block of meta tags from react-helmet as strings and need to render this out in a template.

@ForbesLindesay
Copy link
Member

Your code should be:

html
  head
    != metaTagTest
    != title
  body

This isn't a bug in pug, it is a quirk of how browsers handle nested tags they don't expect you to nest. If you look at the raw HTML output from pug (right click + view source), you will see pug works fine, but the browsers try to "fix" your markup, with varying results for different tags.

@tony99nyr
Copy link
Author

aha! :-D I had no idea the syntax without a tag was valid! I assumed the tag name was required. Thank you very much for taking the time to point out this seemingly obvious solution. Definitely definitely not a bug in pug. Sorry for the misunderstanding. Cheers!

@ForbesLindesay
Copy link
Member

While you're here, maybe you could add something to the docs to clarify this to other people? The docs are at https://github.com/pugjs/pug-en/tree/master/src if you would like to submit a pull request. From these docs, the https://pugjs.org website gets updated daily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants