Page MenuHomePhabricator

subst breaks #if statements on template include
Closed, InvalidPublic

Description

When using subst to transclude a template with '#if' statements, I ended up with a template full of broken statements, where the test part is missing.

E.G.: (Part of) Source template looks like this:

{{#if: {{{born|}}} |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Born:'''
 {{!}} {{{born}}} }}<!-- -->{{#if: {{{died|}}} |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Died:'''
 {{!}} {{{died}}} }}<!-- -->{{#if: {{{alias|}}} |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Aliases:'''
 {{!}} {{{alias}}} }}

but using subst, I end up with this:

{{#if:  |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Born:'''
 {{!}} {{{born}}} }}<!-- -->{{#if:  |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Died:'''
 {{!}} {{{died}}} }}<!-- -->{{#if:  |<nowiki />
 {{!-}}
 {{!}} valign="top" {{!}} '''Aliases:'''
 {{!}} {{{alias}}} }}

If not obvious, the test part of every '#if' statement is missing. I tested this on both my 1.27 installs, happens every single time. I've only tested with if statements, as I don't have templates using any other statements at the moment. This is on my private install (not online). Not sure how to safely test on the live WM server.
WM 1.27.0 / PHP 7.0.9 64bit / Apache 2.4.3 64bit / MySQL 5.0.12 64bit / Windows 7 SP1 64bit

Event Timeline

Danny_B subscribed.

That's intended and correct behavior.

Use

{{safesubst:#if:{{{born|}}}|<nowiki />
 {{!}}-
 {{!}} valign="top" {{!}} '''Born:'''
 {{!}} {{{born}}} }}<!-- -->{{safesubst:#if:{{{died|}}}|<nowiki />
 {{!}}-
 {{!}} valign="top" {{!}} '''Died:'''
 {{!}} {{{died}}} }}<!-- -->{{safesubst:#if:{{{alias|}}}|<nowiki />
 {{!}}-
 {{!}} valign="top" {{!}} '''Aliases:'''
 {{!}} {{{alias}}} }}

etc... in your template.