-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify data return type and permit inheritance of data over layout and fetch #321
base: v3
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,15 +110,15 @@ public function __toString() | |
/** | ||
* Assign or get template data. | ||
* @param array $data | ||
* @return mixed | ||
* @return array | ||
*/ | ||
public function data(array $data = null) | ||
{ | ||
if (is_null($data)) { | ||
return $this->data; | ||
} | ||
|
||
$this->data = array_merge($this->data, $data); | ||
return $this->data = array_merge($this->data, $data); | ||
} | ||
|
||
/** | ||
|
@@ -196,7 +196,7 @@ public function render(array $data = array()) | |
public function layout($name, array $data = array()) | ||
{ | ||
$this->layoutName = $name; | ||
$this->layoutData = $data; | ||
$this->layoutData = array_merge($this->data, $data); | ||
} | ||
|
||
/** | ||
|
@@ -311,9 +311,9 @@ public function section($name, $default = null) | |
* @param array $data | ||
* @return string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the same name variable as twig - see https://twig.symfony.com/doc/3.x/tags/include.html#:~:text=only Is it enough clear ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a second commit and rename it |
||
*/ | ||
public function fetch($name, array $data = array()) | ||
public function fetch($name, array $data = array(), bool $only = true) | ||
{ | ||
return $this->engine->render($name, $data); | ||
return $this->engine->render($name, $only ? $data : array_merge($this->data, $data)); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider to change this documentation to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, should be even :
(Assign|merge with existing) or get template data.
?