macro field_if_set for ephox/edit live fields

Here is one solution to handle a field_if_set for ephox (Edit Live fields). The issue with ephox fields is that you can’t check for length > 0 because of the potential “<p></p>” tags. What the following does (with regexp replaceAll) is it strips out all tags before checking the length…hence the remainder should be content, if there is anything, within the tags. I have noticed that using #__handlefieldaa only opens the div tags when previewing in active assembly, resulting in some nesting divs (hence the explicit calls to start and end AAfield)


#macro(field_if_setEphox $before $field $after)##
#if($sys.item.hasProperty($field))##
#if($sys.item.getProperty($field).String.replaceAll("<.*?>", "").trim().length()> 0)##
$before##
#field($field)##
$after##
#else##
#startAAField($field '')##
#endAAField($field)##
#end##
#end##
#end##