Charlton Roberts

Creative Developer, Squarespace

“Machinery has been taught arithmetic instead of poetry.”
Charles Babbage, 1832

Conditional Parents in Jade

The Problem:

I need to decide which parent to insert based on a conditions. However, whatever the condition, they should both have identical children. Jade does not have an end like Ruby or a fi like bash. And if you simply add another space like you would expect, then only the last condition gets the children. There seems to be some disagreement over whether this is a limitation of the language or merely bad syntax that should be avoided.

Example:

```Javascript if (condition) form.class1(action="/", method="POST") else form.class2(action="/", method="POST")

input(type="text", placholder="Some Input")

```

The Solution:

Jade does support the ternary operator, and it works pretty well with tag attributes (including classes). My particular fix was as follows:

JavaScript form(action="/", method="POST", class=(condition)?'class1':'class2') input(type="text", placholder="Some Input")