monokrome/jaded-brunch

Allow for passing in options to the template

Closed this issue · 8 comments

It would be really nice to allow data to be passed from the config into the compiler via the options object for the plugin.

I submitted a pull request adding this feature. You can now pass in locals to the jade compiler via the plugin config like this:

plugins: {
  jade: {
    pretty: true,

    // These will all get passed to the template
    locals: {
      enviroment: 'development',
      magic: true
    }
  }
}

Then in your template you can use the data that was passed in:

if magic == true
  h1 Magic is on
else
  h1 Magic is off

Hey, @daviesgeek. Thanks for sending over this pull request.

This looks like a duplicate of #11. Would you mind helping me verify whether my comment on that issue solves the problem for you without additional code changes?

Hi @monokrome.

It is a duplicate of #11. I do apologize, as I forgot to check the PRs, I only checked the issues.
It does not solve my problem. On line 138, the wrapped template function (from jade) is being called without passing anything in. Thus, no data will ever get to the template because nothing is being passed in.

Either #11 or #12 should address the issue.

Any update on this?

Closed due to #13 (comment)

@daviesgeek I want to make sure that this issue has been resolved and is working as you would expect. Is everything good now, or is there something else that we should be considering here? Please feel free to reopen the issue if something is still outstanding!

Whoops. Thought this needed reopening. But nevermind :)

I was able to pass options to the template like this:

plugins: {
  jaded: {
    pretty: true,
    locals: {
      environment: 'development',
      magic: true
    }
  }
}

Thanks! Works great!

Cool. I was worried that I merged something bad when I saw that it was reopened. Glad to see it's working as expected! This should work, too - I think:

plugins: {
  jaded: {
    jade: {
      pretty: true,
      locals: {
        environment: 'development',
        magic: true
      }
    }
  }
}