When to use a new layout twig file vs new page?
Created 7 years ago by gwerner

Typically the default layout.twig view contains a simple output to render the inner most guts of a page. As I am building a theme, some pages can have a wildly different layout than what may be considered the "default" layout. When is it better to create a second twig file to handle these different layouts versus creating a new page from within the admin that uses a Page Type/HTML Editor Field Type assignment to output the new layout. It seems like both could handle the task. Which is better for performance, ease of maintaining, etc? What is considered best practice from a CMS perspective?

william  —  7 years ago

Great question. I am developing my first website with Pyro myself, and have been having the same question. I am not sure, and i will spend the Christmas figuring out the workflow that fits me.

I will make sure to revisit this thread. This time around i did create new twig files too often i think. But the reason i did that, is to make sure i can store it in my git repository. I am sure ill figure out the best path for this over Christmas. Would really like to hear about others approaches to this however.


samharrison7  —  7 years ago

I've been asking myself this question too. I guess the main difference between the two is that if you were to use the theme on another site, then the new Twig files would still be there and that particular layout still available, whereas a page type layout wouldn't be. So perhaps a good rule of thumb would be that, if the layout you want is crucial to your theme, then use new Twig files, otherwise if the layout you want is more specific to the site you're actually building (e.g., it's got loads of custom fields that wouldn't necessarily be there if you used your theme on another site), use the page type layout.

Another consideration is if you want clients to have control over the page layout. I can envisage projects where it's essential to keep the layout files as far away from the client as possible! ;)

gwerner  —  7 years ago

@william raises a good point on versioning. I like the idea of being able to keep twig file in my repository. But, I also don't like having to commit if the client makes a content change versus something structural. I feel like content should be in the CMS and not dormant in a twig file. I also think it's easier to edit HTML outside of Pyro. Which is not a fault of Pyro but CMS's in general. Plus, what about layout images? I haven't found an easy way of including those within the CMS. They usually have to be manually dumped into an img/ directory.

Maybe I'm approaching this incorrectly?