ereplacer Extension to replace context of text with whatever you like.

Yii framework extension to replace context of text with whatever you like.

Description and use cases

You can use this extension to replaces 'standar' parts for a string to whatever you like. I will describe my personal use case. In my blog I used to add posts with title like:

  • {yii}{ext} EReadmore
  • {yii}{wiki} A simple...
  • {php} New to ...

This was to categorize the Posts. So one day i wanted to replace all this with some icons. The code below does this work for me. Other use cases can be to display emoticons in text, tags, etc.

Code example

Notice that there is not constrain to use a key=>value array as data. What $data will be depends entirely to you and its related to who you will access that data in the replace eval phrase.

$this->beginWidget('ext.EReplacer', array(
        'bag'=>'{}',
        'data'=>array(
           'yii'=>'http://image src...',
           'wiki'=>'http:///image src...',
           'php'=>'http://image src...',
        ),
        'replace'=>'"<img src=\'".$data[$el]."\' />";',
    ));
    echo $post->title;
    $this->endWidget();

You can as well use the text property like:

$this->widget('ext.EReplacer', array(
        'bag'=>'{}',
        'text'=>$post->title,
        'data'=>array(
           'yii'=>'http://image src...',
           'wiki'=>'http:///image src...',
           'php'=>'http://image src...',
        ),
        'replace'=>'"<img src=\'".$data[$el]."\' />";',
    ));
Thanks

I would like to thank rawtaz, SJFriedl, ciss & robert___ for the regexp help.

5 0
4 followers
533 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Tags: icons, ui
Developed by: tydeas_dr
Created on: Apr 16, 2011
Last updated: 13 years ago

Downloads

show all

Related Extensions