You are here

public function QPTPL::tplArrayR in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/Extension/QPTPL.php \QPTPL::tplArrayR()
  2. 7.2 QueryPath/Extension/QPTPL.php \QPTPL::tplArrayR()
2 calls to QPTPL::tplArrayR()
QPTPL::tpl in QueryPath/Extension/QPTPL.php
QPTPL::tplAll in QueryPath/Extension/QPTPL.php

File

QueryPath/Extension/QPTPL.php, line 63

Class

QPTPL

Code

public function tplArrayR($qp, $array, $options = NULL) {
  if (!is_array($array) && !$array instanceof Traversable) {
    $qp
      ->append($array);
  }
  elseif ($this
    ->isAssoc($array)) {
    foreach ($array as $k => $v) {
      $first = substr($k, 0, 1);
      if ($first != '.' && $first != '#') {
        $k = '.' . $k;
      }
      if (is_array($v)) {
        $this
          ->tplArrayR($qp
          ->top($k), $v, $options);
      }
      else {
        $qp
          ->branch()
          ->children($k)
          ->append($v);
      }
    }
  }
  else {
    foreach ($array as $entry) {
      $eles = $qp
        ->get();
      $template = array();
      foreach ($eles as $ele) {
        $template = $ele
          ->cloneNode(TRUE);
      }
      $tpl = qp($template);
      $tpl = $this
        ->tplArrayR($tpl, $entry, $options);
      $qp
        ->before($tpl);
    }
    $dead = $qp
      ->branch();
    $qp
      ->parent();
    $dead
      ->remove();
    unset($dead);
  }
  return $qp;
}