question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Html var into html

See original GitHub issue

Hi,

First I’ve updated my code with the 5.0.4 api version. Very good work!

Expected behavior

I want to include in my template string a HTML string from a var.

Actual behavior

The html output is a string so by example my img tag is literally outputted as string and no image is shown.

"coucou <img class="emojione" alt="🙂" src="//cdn.jsdelivr.net/emojione/assets/png/1f642.png?v=2.1.2"/>"

Steps to reproduce behavior

Example:

import html from 'choo/html';
import emojione from 'emojione_minimal';

emojione.ascii = true;

module.exports = (input, emit) => {
  return html`
    <div>${emojione.shortnameToImage(input.text)}</div>
  `;
};

I’ve tried with the html() function instead of html`` but bel send an error:

Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': 'emojione"' is not a valid attribute name.

I’ve tried to include my emojione return value into an another var but bel send always a setAttribute error.

Thanks for your help.

Yu.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
greggrafcommented, Mar 29, 2017

@yudao - I saw an error similar to yours when passing a string directly to html() .

It worked when I passed an array of strings as the first argument, which is what tagged templates literals do.

Does this work?

module.exports = (input, emit) => {
  return html(["<div>", emojione.shortnameToImage(input.text), "</div>"]);
};
0reactions
yudaocommented, Mar 30, 2017

@greggraf Sorry for the delay. Awesome tip ! it’s working like a charm !

Thanks all for your help!

Yu.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I use this JavaScript variable in HTML?
You don't "use" JavaScript variables in HTML. HTML is not a programming language, it's a markup language, it just "describes" what the page ......
Read more >
HTML var tag
The <var> tag is used to defines a variable in programming or in a mathematical expression. The content inside is typically displayed in...
Read more >
<var>: The Variable element - HTML - MDN Web Docs - Mozilla
The <var> HTML element represents the name of a variable in a mathematical expression or a programming context.
Read more >
How to add a variable in HTML?
Use the <var> tag in HTML to add a variable. The HTML <var> tag is used to format text in a document. It...
Read more >
How to use the var element in HTML
The <var> element in HTML defines a text as a variable and can be used to define variables of a mathematical expression or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found