Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


I plan to clean up and open source more of my Yii extensions. Please be patient. :)


KHtmlPurifierColumn represents a grid view column that renders purified html in each of its data cells. It also does truncation when specified.

It uses CHtmlPurifier, provided as part of Yii Framework, which is wrapper of HTML Purifier. HTML Purifier removes all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist. It will also make sure the resulting code is standard-compliant.

KHtmlPurifierColumn accepts options from HTML Purifier.

Usage with in CGridView as a column class:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $model->search(),
    'columns' => array(
            'class' => 'ext.kcolumns.KHtmlPurifierColumn',
            'name' => 'content',
            'options' => array(
                'HTML.AllowedElements' => array('i', 'em', 'strong', 'b', 'sup', 'sub'),
                'HTML.AllowedAttributes' => array(),
            'truncate_length' => 250, #Number of characters limit for truncation.
            'truncate_suffix' => '&hellip;', #Ellipses
            'name' => 'id',

In the above example, HTML.AllowedElements is one of the many configuration options of HTML Purifier. Specifying a truncate_length of 250 truncates the content within 250 characters. It also removes all links and style attributes in HTML elements.

Page output

This is an example of what the browser can render using the above example:

Screenshot of KHtmlPurifierColumn

More information