MEM
MEM

Reputation: 31307

How to extend CListView in order to remove extra yii added markup?

The point is to remove from CListView render, those two divs:

<div id="yw0" class="list-view">
<div class="items">

I've been looking here:

https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CBaseListView.php#L123

But I found nothing related with those two divs there.

Can anyone please share, what should we extend in order for make this a reality ?

Here's an update of the desired output:

<div>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
</div>

Upvotes: 3

Views: 2342

Answers (1)

bool.dev
bool.dev

Reputation: 17478

You'd be better off extending from CListView itself, but write new implementations for run() method in CBaseListView and a new implementation for the renderItems() method in CListView, for example:

Yii::import('zii.widgets.CListView');
class MListView extends CListView{
    public function run(){
            $this->registerClientScript();
            // this line renders the first div
            //echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n"; 

            $this->renderContent();
            $this->renderKeys();

            //echo CHtml::closeTag($this->tagName);
    }

    public function renderItems(){
            //this line renders the second div
            //echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n"; 
            // copy original code from the function
            //echo CHtml::closeTag($this->itemsTagName);
    }
}

Edit:

Be aware that some of the default clistview functionality will not work with only this much, because the jquery.yiilistview.js will not work without an id, that identifies this listview.

Edit:

From your updated question, you can do this, then:

<div id="some-id">
<?php
    $this->widget('ext.extendedwidgets.MListView',array(
        'id'=>'some-id', // same id you specified in the div
        //... rest of it
        'template' => '{items}', // as seen in the chat below
    ));
</div>

Upvotes: 2

Related Questions