
# Testing for an empty WYSIWYG field

> A WYSIWYG field can hold plain text or HTML elements, so test both the element's value and whether it has children.

URL: https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/script-formats/testing-for-an-empty-wysiwyg-field.html
category: Developing in Cascade
article-type: how-to
content-kind: faq
release-availability: all
tags: velocity, wysiwyg
updated: 2026-10-06

Testing whether a WYSIWYG field is empty is tricky, because the field can contain either plain text or HTML elements. The reliable approach is to test whether the XML element's value is non-empty *or* the element has children, meaning HTML elements.

## Velocity, with the Cascade API

```velocity
## Record the WYSIWYG field
#set ($wysiwygField = $callingPage.getStructuredDataNode("wysiwyg-field"))
## Test whether the field has a value
#if (!$_PropertyTool.isEmpty($wysiwygField.textValue))
    $wysiwygField.textValue
#end
```

## Velocity, with an Index Block

```velocity
## Record the WYSIWYG field
#set ($wysiwygField = $_XPathTool.selectSingleNode($contentRoot, "//wysiwyg-field"))
## Test whether the element has a value, or has children
#if ($wysiwygField.value != "" || $wysiwygField.getChildren().size() > 0)
    $_SerializerTool.serialize($wysiwygField, true)
#end
```

## XSLT

```xml
<xsl:if test="wysiwygField/node()">
    <!-- use xsl:copy-of so all child nodes and attributes are copied as well -->
    <xsl:copy-of select="wysiwygField/node()"/>
</xsl:if>
```
