Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

I am using the Editor WYSIWYG add-on so that I can have WYSIWYG support in the category description editor. This has been working fine until the following issue arose.

When the category description is left in a way that appears empty, it actually outputs the following <p><br></p> which is bad for three reasons:

  1. It is not XHTML compliant (the <br> should be <br/>).
  2. There is no sense for there to be an <br> element in the first place... it should be blank. Sure I can understand the empty <p> element but why the other?
  3. The following template logic fails to work (primary concern):

{if category_description}
<div class="category-description">{category_description}</div>
{/if}

How can I prevent the Editor add-on from generating junk for when an empty description is specified? or alternatively how can I safely determine when the description is empty?

Note: I do not trust using {if category_description != '<p><br></p>'} for a number of reasons. a) browser compatibility, b) varying results for empty category description, c) it's too hacky

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

For the time being I have created the following plugin to workaround this issue. I am still interested in a proper solution (if there is one) though:

public function excl_empty_html() {
    $this->EE = &get_instance();

    // If content is empty then waste no further time
    $content = trim($this->EE->TMPL->fetch_param('content'));
    if ($content == '')
        return '';

    // Strip HTML tags and trim to determine if there is any physical content.
    if (trim(strip_tags($content)) == '')
        return '';

    // Finally parse output
    $variables[] = array(
        'content' => $content
    );
    return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables);
}

Usage:

{exp:yourplugin:excl_empty_html content="{category_description}"}
    <div class="category-description">{content}</div>
{/exp:yourplugin:excl_empty_html}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.