Bill Proxima Chandler
Bill Proxima Chandler

Reputation: 117

Jade. Passing plain text variable to title

Beginner working with jade and i'm moving onto using variables. I have three files: docwrapper.jade (the template), example.jade (the content) and config.jade (the variables).

I have set a very basic variable in config.jade - var PageTitle = "Jade"

It is then supposed to insert itself in my docwrapper.jade:

include config

doctype
html
  head
    block metatags
      meta(charset="utf-8")
      meta(http-equiv="X-UA-Compatible", content="IE=edge")
      meta(name="viewport",content="width=device-width,initial-scale=1.0")     
    title 
      block title
        | #{PageTitle}
    block stylesheets
      link(href="assets/css/stylesheet.css",rel="stylesheet")
  body
    nav
      .wrapper
        a.global-nav(href="#")
          img.global-nav(href="#")
        span.page-footer
          block headertext
            | Default Content
    section.wrapper
      block content

But when the file compiles there is no title. If I insert the variable PageTitle anywhere else in the code then it appears (eg. inside block headertext). If I, however, inside example.jade (which extends docwrapper) add:

block title
  | Some Text Here

It then changes on the page. It even works if I put the variable in there.

From my understanding whatever I put inside the docwrapper.jade under block title should be the default output for it so that if there is no mention of block title inside the example.jade then the output should use the default.

I can upload the entire three files for someone to look at if necessary. Any ideas?

Upvotes: 1

Views: 930

Answers (1)

fregante
fregante

Reputation: 31718

Use block prepend, this way what you already have in there will stay there and new content will be added before it.

docwrapper.jade

title 
  block prepend title
    | #{PageTitle}

example.jade

extend docwrapper.jade
block title
  | Some Text Here

Upvotes: 2

Related Questions