RejectedSoftware Forums

Sign up

Diet templates conditional attributes

Hello!

I found this in the Jade documentation, but can't get it to work here.

Example:

- if (autofocus)
    input(type="text", autofocus="#{autofocus ? "autofocus" : null}")

The autofocus element should disappear if autofocus == false, but it leaves it there with an empty string.

If this isn't implemented, how can I get optional attributes without exponentially blowing up if conditions?

Thanks, Matej

Re: Diet templates conditional attributes

Am 28.01.2013 22:45, schrieb Matej Nanut:

Hello!

I found this in the Jade documentation, but can't get it to work here.

Example:

- if (autofocus)
   input(type="text", autofocus="#{autofocus ? "autofocus" : null}")

The autofocus element should disappear if autofocus == false, but it leaves it there with an empty
string.

If this isn't implemented, how can I get optional attributes without exponentially blowing up if
conditions?

Thanks, Matej

A similar way to do this has just been implemented in the latest version. If autofocus is a
boolean value then this should work:

input(type="text", autofocus=autofocus)

Arbitrary D-expressions are now supported for attribute values. It doesn't work inside of a string
interpolation or using a ternary operator, though, because of D's statically typed nature.

Re: Diet templates conditional attributes

Fantastic! I'll give it a spin after work.

Re: Diet templates conditional attributes

Seems to work perfectly, thanks!