| @@ 98-132 (lines=35) @@ | ||
| 95 | * |
|
| 96 | * @return self for chaining. |
|
| 97 | */ |
|
| 98 | public function add($template, $data = [], $region = "main", $sort = 0) |
|
| 99 | { |
|
| 100 | if (empty($template)) { |
|
| 101 | return $this; |
|
| 102 | } |
|
| 103 | ||
| 104 | $view = new View(); |
|
| 105 | ||
| 106 | if (is_string($template)) { |
|
| 107 | $tpl = $this->getTemplateFile($template); |
|
| 108 | $type = "file"; |
|
| 109 | } elseif (is_array($template)) { |
|
| 110 | // Can be array with complete view or array with callable callback |
|
| 111 | $tpl = $template; |
|
| 112 | $type = null; |
|
| 113 | $region = isset($tpl["region"]) |
|
| 114 | ? $tpl["region"] |
|
| 115 | : $region; |
|
| 116 | ||
| 117 | if (isset($tpl["callback"])) { |
|
| 118 | $tpl["template"] = $template; |
|
| 119 | $tpl["type"] = "callback"; |
|
| 120 | } elseif (isset($tpl["template"])) { |
|
| 121 | if (!isset($tpl["type"]) || $tpl["type"] === "file") { |
|
| 122 | $tpl["type"] = "file"; |
|
| 123 | $tpl["template"] = $this->getTemplateFile($tpl["template"]); |
|
| 124 | } |
|
| 125 | } |
|
| 126 | } |
|
| 127 | ||
| 128 | $view->set($tpl, $data, $sort, $type); |
|
| 129 | $this->views[$region][] = $view; |
|
| 130 | ||
| 131 | return $this; |
|
| 132 | } |
|
| 133 | ||
| 134 | ||
| 135 | ||
| @@ 66-100 (lines=35) @@ | ||
| 63 | * |
|
| 64 | * @return self for chaining. |
|
| 65 | */ |
|
| 66 | public function add($template, $data = [], $region = "main", $sort = 0) |
|
| 67 | { |
|
| 68 | if (empty($template)) { |
|
| 69 | return $this; |
|
| 70 | } |
|
| 71 | ||
| 72 | $view = new View(); |
|
| 73 | ||
| 74 | if (is_string($template)) { |
|
| 75 | $tpl = $this->getTemplateFile($template); |
|
| 76 | $type = "file"; |
|
| 77 | } elseif (is_array($template)) { |
|
| 78 | // Can be array with complete view or array with callable callback |
|
| 79 | $tpl = $template; |
|
| 80 | $type = null; |
|
| 81 | $region = isset($tpl["region"]) |
|
| 82 | ? $tpl["region"] |
|
| 83 | : $region; |
|
| 84 | ||
| 85 | if (isset($tpl["callback"])) { |
|
| 86 | $tpl["template"] = $template; |
|
| 87 | $tpl["type"] = "callback"; |
|
| 88 | } elseif (isset($tpl["template"])) { |
|
| 89 | if (!isset($tpl["type"]) || $tpl["type"] === "file") { |
|
| 90 | $tpl["type"] = "file"; |
|
| 91 | $tpl["template"] = $this->getTemplateFile($tpl["template"]); |
|
| 92 | } |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | $view->set($tpl, $data, $sort, $type); |
|
| 97 | $this->views[$region][] = $view; |
|
| 98 | ||
| 99 | return $this; |
|
| 100 | } |
|
| 101 | ||
| 102 | ||
| 103 | ||