Menu

#21 Optional fields are problematic for template authors

open
nobody
5
2008-04-10
2008-04-10
No

At our site, we don't always use the story subhead field, but sometimes we do.

This is problematic when writing story templates. For example, let's say I use the <h1> tag for headlines, and the <h2> tag for subheads. This will work fine if the story being viewed has a subhead. For those that don't, however, PROPS will render an empty <h2> tag ("<h2></h2>"), which causes spacing issues.

Similarly: we don't always use the media credit suffix, because it doesn't always make sense.

Our templates render media credits as "(Credit line/Credit line suffix)" - for example, "(John Smith/Staff Photographer)". However, if a photo comes from the AP, it appears as "(AP photo/)".

It would be nice if the PROPS templating system offered some way to address these and similar cases. Consider this solution:

{subhead format='<h2>%s</h2>'}

If the subhead field is empty, this tag would output nothing; otherwise, it would output the subhead wrapped in <h2> tags.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.