Added sections inheritance of fetched templates#306
Conversation
section mode handling is still missing though
|
My latest commit now addresses my comments. |
|
Let's add a test to highlight the bug, and then also we'd need to support this in the Another solution which might work fine is:
Your solution isn't bad, but having one mutable class that defines the API clearly might simplify the solution. |
|
@ragboyjr I agree with you, I don't know if I can find time any sooner to do that though. Maybe next weekend. |
|
@ragboyjr my latest commit addresses the need for a TemplateSections API and defines the base for the implementation of the other ideas you gave. I'd like you to take a look at this initial stage and help me define the next steps. |
|
I've added more template section tests. |
| $layout = $this->engine->make($this->layoutName); | ||
| $layout->sections = array_merge($this->sections, array('content' => $content)); | ||
| $layout->sections->merge($this->sections); | ||
| $contentSectionName = 'content'; |
There was a problem hiding this comment.
Suggest to use a attribute to declare it. In case someone want to change it.
basteyy
left a comment
There was a problem hiding this comment.
I like the changes, and it seems to me that this works fine.
| $this->mode = $mode; | ||
|
|
||
| // if this template doesn't have that section, so we just add it. | ||
| if (empty($this->content)) { |
There was a problem hiding this comment.
I like !isset instead of empty. Some time ago I read that this would be faster.
There was a problem hiding this comment.
I think it's because empty also checks if the value represents an empty value like "".
Let the template knows the parent and reuse the parent's section may solve this issue. I think that's more proper point of view on this problem-space. I mean, diff --git a/src/Template/Template.php b/src/Template/Template.php
index 21c66f0..b096633 100644
--- a/src/Template/Template.php
+++ b/src/Template/Template.php
@@ -40,6 +40,8 @@ class Template
*/
protected $data = array();
+ protected $parent;
+
/**
* An array of section content.
*
@@ -77,11 +79,12 @@ class Template
* @param Engine $engine
* @param string $name
*/
- public function __construct(Engine $engine, $name)
+ public function __construct(Engine $engine, $name, $parent = null)
{
$this->engine = $engine;
+ $this->parent = $parent;
$this->name = new Name($engine, $name);
- $this->sections = new TemplateSectionCollection();
+ $this->sections = $this->parent ? $this->parent->sections : new TemplateSectionCollection();
$this->data($this->engine->getData($name));
}
|
|
Ah, I see some complication when using |
|
I think referencing the same sections as the parent template does is exactly one of the things we want to avoid. IN my understanding the Render should handle reading all sections and put them all together accordingly to whats registered in each template. |
|
@Abdillah could you add the scenario for the issues you saw with using layout so I can make a test for it? |
|
I'm on vacation, I'll be back tomorrow. |
|
ping @Abdillah |
|
Hello, I'm sorry for not responding soon. I've written some of my though in this comment (quoted below). I expect Plates to overwrite section when multiple child template using
|
|
Hello @Abdillah sorry the enormous delay. I feel down with this project given it feels abandoned, but let's talk about this PR. Your previous comment describes exactly what I implemented here, when you use Anyways, if @ragboyjr gives this some attention I'd be happy to finish this implementation. |
This PR partially addresses the case described in #305 , it still lacks considering the section mode of each of the appended sections where you can append, prepend or replace the sections entirely. Unfortunately we don't current store how the sections where filled in the template so it is currently impossible to know that during the inheritance in the parent template. My current best idea for that is to create yet a new property called
$sectionsAddedModeso we can track per section name the mode used during the push/unshift/replace, e.g.$sectionsAddedMode = [ 'head' => 1, 'appbar' => 1, 'footerScripts' => 2 ].