(Quick Reference)

p:attrIfSet

Purpose

Writes out an HTML attribute only if the value for it is non-null.

Useful for keeping HTML output clean when some model or other attribute may be null and hence the attribute should not be written out at all.

Example

{docx:xml} <img src="…" ${p.attrIfSet(value:imgW, name:'width')} ${p.attrIfSet(value:imgH, name:'height')} ${p.attrIfSet(value:altText, name:'alt')}/> {docx}

Attributes

NamePurpose
nameRequired - The name of the attribute
valueRequired - The value of the attribute. Null values will mean nothing is written.