Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the style tag with jade templates?

Tags:

pug

This style code worked for me a few months back. I have updated to the latest Jade NPM package and now it is not working. Can some please assist me with the proper way to inline a style in a Jade template?

doctype 5
html(lang="en")
    head
        style(type='text/css')
           .ui-title {
                margin: 0.6em 10% 0.8em !important;
            }

I get this error on the closing }

unexpected text }
like image 346
MobileGuy Avatar asked Feb 13 '14 20:02

MobileGuy


People also ask

How do I add a pug in HTML?

Try Pug HTML without Installing Simply create a new pen, then select Settings > HTML and choose Pug as your preprocessor. This will allow you to enter Pug code into the HTML pane and see the result appear in real time.

What is the use of a jade template?

Jade is a template engine for Node.js. Jade syntax is easy to learn. It uses whitespace and indentation as a part of the syntax.

How to use Jade with express JS to create HTML pages dynamically?

Express.js can be used with any template engine. Here, we will use different Jade templates to create HTML pages dynamically. In order to use Jade with Express.js, create sample.jade file inside views folder and write following Jade template in it.

What are the advantages of jade over HTML?

The main advantage of Jade is that this text renders both closing and opening tags for the HTML element, as well as the <></> symbols. Therefore, we save many keystrokes as developers writing in Jade! The text following a tag and a space (e.g., tag <text>) is parsed as the inner HTML (i.e., content inside the element).

How do I convert Jade to HTML?

If you want to try this out as we go along, you can use CodePen and choose Jade as your HTML preprocessor or use the online compiler on the official Jade page to compile your Jade to HTML. As you might have noticed earlier, there are no “closing” tags in Jade.


2 Answers

This worked for me:

style.
  body {
    background-color: {{themeColor}};
  }

Got it from: https://github.com/mquandalle/meteor-jade/issues/102 where the post suggests to use "dot notation"

like image 82
Gene Bo Avatar answered Oct 23 '22 01:10

Gene Bo


There are three ways of putting text inside your tags in Jade

1. Put text just after the tag e.g.

h1 Some header text

And the output will be:

<h1>Some header text</h1>

2. Put indented text below the tag with | e.g.

p
    | Some text goes 
    | here

And the output will be:

<p>Some text goes here</p>

3. Suffix the tag with a dot and indent your text below (with no |) e.g.

p.
    This way 3rd way of putting 
    text inside

And the output will be:

<p>This way 3rd way of putting text inside</p>

So based on the above, the approach you chose (as in your comment) is correct (option 3).

doctype 5
html(lang="en")
    head
        style(type='text/css').
           .ui-title {
                margin: 0.6em 10% 0.8em !important;
            }

I hope that will help.

like image 67
Tom Avatar answered Oct 22 '22 23:10

Tom