user393964
user393964

Reputation:

How to call custom filters in Zend?

I want to use htmlpurifier on my website, but can't figure out how to load my filter in the view. I've added my filter the way described in the first answer here.

I want to be able to call it from my view with something like $this->filter($content) Any suggestions how I do that?

Upvotes: 2

Views: 399

Answers (1)

Boris Guéry
Boris Guéry

Reputation: 47585

It is a two step process:

  1. Write an actual Zend_Filter implementation of HTMLPurifier (done, answer in the question you mentioned)
  2. Write a view helper

It will look like this:

class My_View_Helper_Purify extends Zend_View_Helper_Abstract
{
   public function purify($value)
   {
       $filter = new My_Filter_HtmlPurifier();

       return $filter->filter($value);
   }
}

Don't forget to add your custom view helper path:

    $view->addHelperPath(
        APPLICATION_PATH . '/../library/My/View/Helper',
        'My_View_Helper_'
    );

And later in any of your view scripts:

<?= $this->purify($text) ?>

Upvotes: 6

Related Questions