Development

Testing for an empty WYSIWYG field

Testing to see if a WYSIWYG field can be tricky since the field could either contain plain text or HTML elements.

One solution is to test if the value of an XML Element is not empty, or if the Element contains children (ie the HTML elements).

Using Velocity

With the Cascade API

## Record the WYSIWYG field
#set ($wysiwygField = $callingPage.getStructuredDataNode("wysiwyg-field")) 
				
## Test to see if the field's value is not empty
#if (!$_PropertyTool.isEmpty($wysiwygField.textValue))
    $wysiwygField.textValue
#end

With an Index Block

## Record the WYSIWYG field
#set ($wysiwygField = $_XPathTool.selectSingleNode($contentRoot, "//wysiwyg-field")) 

## Test to see if the Element's value is not empty, or if the Element has children
#if ($wysiwygField.value != "" || $wysiwygField.getChildren().size() > 0)
    $_SerializerTool.serialize($wysiwygField, true)
#end

Using XSLT

<xsl:if test="wysiwygField/node()">
    <!-- use xsl:copy-of here to make sure that all child nodes and attributes are copied as well -->
    <xsl:copy-of select="wysiwygField/node()"/>
</xsl:if>