Better handling of complex {{#if}} targets

See #1812