Page MenuHomePhabricator

D630.diff
No OneTemporary

D630.diff

diff --git a/mvc/View.php b/mvc/View.php
--- a/mvc/View.php
+++ b/mvc/View.php
@@ -7,9 +7,9 @@
use spitfire\io\template\Layout;
use spitfire\io\template\Template;
-class View extends MVC
+class View
{
- private $data = Array();
+ private $data = [];
private $template;
private $layout;
@@ -24,7 +24,6 @@
*/
public function __construct(Context$context) {
- parent::__construct($context);
#Get the answer format
$this->extension = $context->request->getPath()->getFormat();
@@ -42,11 +41,21 @@
/**
* Defines a variable inside the view.
- * @param String $key
+ *
+ * @param string $key
* @param mixed $value
+ * @param string $format
*/
- public function set($key, $value) {
- $this->data[$key] = $value;
+ public function set($key, $value, $format = '*')
+ {
+ /**
+ * The user can select an optional format for the
+ */
+ if (!isset($this->data[$format])) {
+ $this->data[$format] = [];
+ }
+
+ $this->data[$format][$key] = $value;
return $this;
}
@@ -84,30 +93,49 @@
else { throw new FileNotFoundException('File ' . $filename . ' not found. View can\'t use it as layout'); }
}
+ /**
+ *
+ * @deprecated since v0.2
+ */
public function element($file) {
$candidates = $this->app->getTemplateLocator()->element($file, 'php');
return new ViewElement($candidates, $this->data);
}
+ /**
+ *
+ * @deprecated since v0.2
+ */
public function setRenderTemplate($set) {
if ($set === false) {
$this->template = null;
}
}
+ /**
+ *
+ * @deprecated since v0.2
+ */
public function setRenderLayout($set) {
$this->render_layout = $set;
}
- public function render () {
+ public function render ($format = 'html')
+ {
#If the template is not to be rendered at all. Use this.
if (!$this->template) { echo $this->data['_SF_DEBUG_OUTPUT']; return; }
try {
- $output = $this->template->render($this->data);
+ /**
+ * Merge the format specific data with the generic data and render the template.
+ * This allows the application to provide format specfic data to the view.
+ */
+ $data = array_merge($this->data['*'], $this->data[$format]?? []);
+ $output = $this->template->render($data);
+ #TODO: The template thing should be replaced with template inheritance ASAP
if ($this->layout && $this->layout->renderable()) {
- $output = $this->layout->content($output)->render($this->data);
+ $output = $this->layout->content($output)->render($data);
}
return $output;

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 13, 10:03 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6152
Default Alt Text
D630.diff (2 KB)

Event Timeline