Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jade undefined variable

jade undefined variable

Problem

Here is an example jade input:

The class variable is undefined

input.class(name="class", type="textfield", value="#{locals.class}")

This shows up as a form with undefined already set as the value. That's not what I want, if it's undefined then no text should appear.

I can also do this:

-if (locals.class) {
input.class(name="class", type="textfield", value="#{locals.class}")
- } else {
input.class(name="class", type="textfield", value="")
- }

But it seems fairly terrible/unusable if I have to do this for every input in every form across the app.

Is there anything I can do about this?

Problem courtesy of: Harry

Solution

Simple fix, you just have to have to remove the quotes and braces and it will print an empty string

input.class(name="class", type="textfield", value=locals.class)
Solution courtesy of: Donnie H

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

jade undefined variable

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×