Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:33:19+00:00 2026-06-16T00:33:19+00:00

What I’m trying to accomplish. What I’m trying to do is actually really simple

  • 0

What I’m trying to accomplish.

What I’m trying to do is actually really simple and the Jade template engine should be able to help me out quite a bit with it, but I’m running into some snags.

I’m building a site that uses a lot of semi-transparent elements like the one in this jsFiddle: http://jsfiddle.net/Chevex/UfKnM/
In order to make the container background be semi-transparent but keep the text opaque this involves 3 elements:

  • A container DIV with position: relative
  • A child DIV with position: absolute, a background color, height/width set to 100%, and its opacity set to the desired level.
  • Another child DIV for the content with no special positioning.

It’s pretty simple and I use it fairly effectively on CodeTunnel.com.

How I want to simplify it.

I’m re-writing CodeTunnel.com in node.js and the Jade template engine seems like it could greatly simplify this piece of markup that I re-use over and over again. Jade mixins look promising so here’s what I did:

  1. I defined a mixin so I could just use it wherever I need it.

    mixin container
        .container(id=attributes.id) // attributes is an implicit argument that contains any attributes passed in.
            .translucentFrame
            .contentFrame
                block // block is an implicit argument that contains all content from the block passed into the mixin.
    
  2. Use the mixin, passing in a block of content:

    +container#myContainer
        h1 Some test content
    

    Generates:

    <div id="myContainer" class="container">
        <div class="translucentFrame"></div>
        <div class="contentFrame">
            <h1>Some test content</h1>
        </div>
    </div>
    

So far everything works great! There is just one problem. I want to use this mixin in a layout.jade template and I want the child template to be able to use block inheritance. My layout.jade file looks like this:

doctype 5
mixin container
    .container(id=attributes.id)
        .translucentFrame
        .contentFrame
            block
html
    head
        title Container mixin text
    body
        +container#bodyContent
            block bodyContent

Then in another jade file (index.jade) I extend layout.jade:

extends layout

block bodyContent
    h1 Some test Content

Everything looks to be in order but the jade parser fails:

I assume it has something to do with the block keyword conflicting. Inside a mixin block is an implicit argument containing the block passed into the mixin, but when extending a jade template block is a keyword that identifies a block of markup that is to be substituted in the equivalent block in the parent template.

If I replace the block bodyContent that I’m passing into the mixin with any other markup then everything works fine. It’s only when I try to pass in a block definition that it gets upset.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:33:20+00:00Added an answer on June 16, 2026 at 12:33 am

    I’d suspect that, because mixins define their own functions, the block bodyContent is being defined in different scope inaccessible from index.jade.

    What you can try instead is to move the use of the mixin to the inheriting view since mixins are “hoisted”:

    layout.jade:

    doctype 5
    
    mixin container
        .container(id=attributes.id)
            .translucentFrame
            .contentFrame
                block
    
    html
        head
            title Container mixin text
        body
            block bodyContent
    

    index.jade:

    extends layout
    
    block bodyContent
        +container#myContainer
            h1 Some test content
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.