Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Allow PHP Renderer to Extends other templates. #171

Closed
wants to merge 3 commits into from
Closed

Allow PHP Renderer to Extends other templates. #171

wants to merge 3 commits into from

Conversation

cgaube
Copy link

@cgaube cgaube commented Nov 27, 2018

Added a new function at the renderer level so that current template extends others.

e.g

template.phtml

<?php 
$this->extendsTemplate('parent_template');
?>

[template content.]

parent_template.phtml

Above template.phtml
<?php echo $this->content ?>
Under template.phtml

Will generate

Above template.phtml
[template content.]
Under template.phtml

aft-christophe added 3 commits November 26, 2018 19:20
Allow templates to extend other templates.
@froschdesign
Copy link
Member

@aft-christophe
Have you seen the concept of children for view models?

https://docs.zendframework.com/zend-view/quick-start/#nesting-view-models

@cgaube
Copy link
Author

cgaube commented Nov 27, 2018

Hi @froschdesign
Yes I am aware of nesting view models, but unfortunately it does not work very well with applications like zend-expressive - Where you you pass a template name to the renderer
https://docs.zendframework.com/zend-expressive/v3/features/template/intro/

I know you could pass the a ViewModel with a child model as layout but it make more sense to "extends" from the template file itself.
I want to keep my handlers / controllers as detached as possible from my templating renderer (So it can be switched without much headaches).

Similar to how most of Templating systems do it out there
Twig -> https://twig.symfony.com/doc/2.x/tags/extends.html
Blade -> https://laravel.com/docs/5.7/blade#extending-a-layout
Not to sure about plates -> http://platesphp.com/v3/templates/inheritance/

How would you tackle this scenario:
I want to use a layout AND a parent template :

  • template
  • parent
  • Layout

Thank you

@froschdesign
Copy link
Member

froschdesign commented Nov 27, 2018

@aft-christophe
Please add these kind of informations always to the description of the pull request otherwise nobody knows the reason or the motivation for your contribution. Thanks!

@cgaube
Copy link
Author

cgaube commented Dec 4, 2018

Closing this PR -
I was able to achieve same effect by using the FilterChain from the render function instead and Custom View Helpers.

@cgaube cgaube closed this Dec 4, 2018
@froschdesign
Copy link
Member

froschdesign commented Dec 4, 2018

@aft-christophe
It would be good if you would add your solution here. Maybe we can use it to create a cookbook recipe for the documentation.

Thank you in advance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants