Pop\Dom\Child::render PHP Method

render() public method

Method to render the child and its child nodes.
public render ( boolean $ret = false, integer $depth, string $indent = null ) : void
$ret boolean
$depth integer
$indent string
return void
    public function render($ret = false, $depth = 0, $indent = null)
    {
        // Initialize child object properties and variables.
        $this->output = '';
        $this->indent = null === $this->indent ? str_repeat('    ', $depth) : $this->indent;
        $attribs = '';
        $attribAry = array();
        // Format child attributes, if applicable.
        if (count($this->attributes) > 0) {
            foreach ($this->attributes as $key => $value) {
                $attribAry[] = $key . "=\"" . $value . "\"";
            }
            $attribs = ' ' . implode(' ', $attribAry);
        }
        // Initialize the node.
        $this->output .= "{$indent}{$this->indent}<{$this->nodeName}{$attribs}";
        if (null === $indent && null !== $this->indent) {
            $indent = $this->indent;
            $origIndent = $this->indent;
        } else {
            $origIndent = $indent . $this->indent;
        }
        // If current child element has child nodes, format and render.
        if (count($this->childNodes) > 0) {
            $this->output .= ">\n";
            $new_depth = $depth + 1;
            // Render node value before the child nodes.
            if (!$this->childrenFirst) {
                $this->output .= null !== $this->nodeValue ? str_repeat('    ', $new_depth) . "{$indent}{$this->nodeValue}\n" : '';
                foreach ($this->childNodes as $child) {
                    $this->output .= $child->render(true, $new_depth, $indent);
                }
                $this->output .= "{$origIndent}</{$this->nodeName}>\n";
                // Else, render child nodes first, then node value.
            } else {
                foreach ($this->childNodes as $child) {
                    $this->output .= $child->render(true, $new_depth, $indent);
                }
                $this->output .= null !== $this->nodeValue ? str_repeat('    ', $new_depth) . "{$indent}{$this->nodeValue}\n{$origIndent}</{$this->nodeName}>\n" : "{$origIndent}</{$this->nodeName}>\n";
            }
            // Else, render the child node.
        } else {
            if (null !== $this->nodeValue || $this->nodeName == 'textarea') {
                $this->output .= ">";
                $this->output .= "{$this->nodeValue}</{$this->nodeName}>\n";
            } else {
                $this->output .= " />\n";
            }
        }
        // Return or print the rendered child node output.
        if ($ret) {
            return $this->output;
        } else {
            echo $this->output;
        }
    }

Usage Example

Example #1
0
 /**
  * Render the child and its child nodes
  *
  * @param  boolean $ret
  * @param  int     $depth
  * @param  string  $indent
  * @param  string  $errorIndent
  * @return mixed
  */
 public function render($ret = false, $depth = 0, $indent = null, $errorIndent = null)
 {
     $datalist = parent::render(true, $depth, $indent) . $this->datalist->render(true, $depth, $indent);
     // Return or print the rendered child node output.
     if ($ret) {
         return $datalist;
     } else {
         echo $datalist;
     }
 }
All Usage Examples Of Pop\Dom\Child::render