views:

33

answers:

1

In a custom decorator, I'm wrapping the element content with a div. This code creates a div around both the <dt> label and the <dd> element

public function render($content)
{        
   return '<div class="test">' . $content . '</div>';
}

Is there a way I can further access those 2 parts, the dd and dt. Such as maybe wrap the div around only the <dt> or the <dd>. How do I access the different parts of $content?

+2  A: 

If it is not that necessary to create a custom decorator for what you want to achieve, you can try decorating the element directly like the following:

$elementDecorators = array( 'ViewHelper', array(array('element'=>'HtmlTag'), array('tag' => 'dd')), array('Label', array('tag' => 'dt')), array(array('wrapper'=>'HtmlTag'), array('tag' => 'div')), );

that shud produce a markup like so:

<div> <dt><label/></dt> <dd><input/></dd> </div>

and so if you want to add anything you want within/between/before/after the dd or dt you can modify as thus:

$elementDecorators = array( 'ViewHelper', array(array('addition'=>'HtmlTag'), array('tag' => 'span')), array(array('element'=>'HtmlTag'), array('tag' => 'dd')), array('Label', array('tag' => 'dt')), array(array('wrapper'=>'HtmlTag'), array('tag' => 'div')), );

that shud produce:

<div> <dt><label/></dt> <dd><span><input/></span></dd> </div>

which just wraps a span tag around the element before the dd tag does.

after decorating you can simply add the variable as the decorator of the element.

burntblark