1

I am using ember js. How do I load a css style sheet from a handlebars js template

For example this doesn't work

<script type="text/x-handlebars" id="about">
    <link rel="stylesheet" href="/static/css/about.css"}}
    // HTML CONTENT
    .......
</script>
6
  • 1
    Try fixing the }} at the end of the <link line. If that doesn't work, you may need to load the css using javascript. Commented Jan 23, 2014 at 3:41
  • 1
    link tags should always be placed in the head of the DOM (per W3C recommendation). If you need to split apart your stylesheet, I suggest using controllers to trigger view methods that manage the stylesheets. I can see the appeal of just putting a stylesheet into a hbs template, but it may produce unwanted effects for some of your visitors. Commented Jan 23, 2014 at 5:32
  • Thanks @MatthewBlancarte I would appreciate a jsfiddle. Not quite got my head around views yet. Commented Jan 23, 2014 at 10:13
  • @MatthewBlancarte also what side effects? Commented Jan 25, 2014 at 5:25
  • Take a look at this thread: stackoverflow.com/q/5828365/614152 Commented Jan 25, 2014 at 16:22

1 Answer 1

1

It looks like it works to me.

<script type="text/x-handlebars" data-template-name="color">
  <h3>Color</h3>
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
  The color of the day is: {{color}}
</script>

http://emberjs.jsbin.com/OxIDiVU/162/edit

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.