2

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

1 Answer 1

1

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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