Barleby February 2016

Jade Include not working (on Extended template)

Simple question: I'm starting a new small project where I have 1 jade file for variables,1 jade file for layout,1 jade file for mixins and finally 1 file for a template.

When I try to use imported variables from the external file, they aren't being loaded into the template, whereas the mixins do.

When page1.jade is processed, mixins are imported correctly, layout is extended correctly, but variable from styles.jade is not imported (or that is what is seems) as the mixins is unable to reach the variable styleCenterMain to be assigned to the style attribute).

page1.jade:

include mixins.jade
include styles.jade
extends layout.jade

block append wholeContent   

block append wholeContent
    div.test1 Hi world

block append wholeContent
    div.test2 Hi Again

block append wholeContent   
    +moduleMain()
        p Some content to pass to mixin

mixins.jade: (Here is where a get the Error.)

mixin moduleMain()
  table(style=styleCenterMain width="100%" height="100%")          

style.jade.

- styleCenterMain ="margin-left: 0; margin-top: 0; margin-right: 0; margin-bottom: 0; padding-bottom: 0; padding-top: 0; padding-right: 0; padding-left: 0; vertical-align: top;"

layout.jade (xml file):

<?xml version="1.0"?>
doctype html

    head        

    body
        <!-- main content -->   

        div(style="background-color:#f2f4f5; margin:0 auto;")
            block wholeContent              

Can anyone give a hint of why style.jade is not imported or why its variable are not accessed by the mixin?

Thanks a lot beforehand

Answers


FabioCosta February 2016

First of all you included styles and named style I would check on that.

Mixins are a good way for you to pass a variable to the included script but they have to receive it, they have their own scope!

If you fix the import name and do this it should solve it:

mixins.jade

mixin moduleMain(desiredStyle)
  table(style=desiredStyle width="100%" height="100%")  

page1.jade

....
block append wholeContent   
+moduleMain(styleCenterMain)
    p Some content to pass to mixin

Post Status

Asked in February 2016
Viewed 2,975 times
Voted 4
Answered 1 times

Search




Leave an answer