thephpleague / plates

Native PHP template system
https://platesphp.com
MIT License
1.47k stars 180 forks source link

Question: setting the layout on object level #41

Closed happyDemon closed 10 years ago

happyDemon commented 10 years ago

Hey there, I've just started using Plates and find it to be an awesome project.

However I was wondering about something, namelyI find it to be a slight hassle having to define the parent layout in every template file, manually.

Wouldn't it be easier to also have the ability to define a master layout on object level, making it easier to change it if needed and not having to hard-code it in every template file.

I want to stress I'm new to plates, so if there's any functionality like this is already in place would you mind pointing me in the right direction?

Thanks ^^

reinink commented 10 years ago

Hey @happyDemon, thanks for stopping by. I'm happy to help answer your question.

Currently this is not possible with Plates. The biggest reason being that you don't want all your templates to implement the master layout. Plates encourages breaking templates into smaller, reusable pieces that together "build up" your pages. Many of these smaller templates don't implement the master layout. Consider things like sidebars, reusable blocks of content, emails, etc.

Generally defining a layout for each page works out well anyway, since you'll often want to pass data it, such as a page title:

<?php $this->layout('template', ['title' => 'User Profile']) ?>

Further, since Plates abstracts the filesystem away from the templates, you really shouldn't have to change the layout very often, if ever. For example, almost all my projects reference the layout at partials/template.

Hope that makes sense!