I
I
ImPuuLsE2015-02-12 16:00:09
Yii
ImPuuLsE, 2015-02-12 16:00:09

How to implement widget display in text in Yii?

Hello! The text has this kind of patterns - [town] and [slider] , which I want to replace. Everything is ok with town (because it's a string), but with slider it's a widget for me. Actually function:

public function modifyContent($content){
    $patterns['townName'] = "[\[town\]]";
    $patterns['slider'] = "[\[slider\]]";

    $replacements['townName'] = $this->getTown()->vname;
                //тут соответсвенно выдает ошибку: Object of class BxSlider could not be converted to string и с этим не поспоришь
    $replacements['slider'] = $this->widget('application.widgets.BxSlider.BxSlider');

    return preg_replace($patterns, $replacements, $content);
  }

Help to implement this functionality, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
werdender, 2015-02-12
@werdender

Something like this:

ob_start();
$this->widget('application.widgets.BxSlider.BxSlider');
$slider = ob_get_contents();
ob_end_clean();
$replacements['slider'] = $slider;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question