Custom page content - best way to do it

Hi all, I’m new to roots, but do have a little WP experience.

I’m trying to work out the best way to approach the templates of a website: The design has almost unique content layouts for each page.

That is to say that the about page content layout is completely different to the service page content layout, which is different to the projects page content etc. To handle the different layouts I’ll be making extensive use of the Advanced Custom Fields plugin.

The header and footer are slightly different for the home page, but always the same for the content pages.

I understand that I could create a page-about.php and it’s corresponding base.php for each of these content pages. However because header and footer of these pages are almost the same it seems like a waste to simply have duplicate versions of these files with different names.

Is there a better way to do it > I initialy though that this would be to create the different content layouts inside the templates directory, so that they all still call the same base files?

I’m unsure if the above is possible - can anyone suggest a good way of doing this. I’d like to keep the code as clean as possible and uphold the Roots ‘don’t duplicate’ idea.

Thanks

There’s no necessary “right” or “wrong” way to go about this. And it really depends on the design you are working with.

Just the page content? Then yes, set up a page-{name}.php file, and call a specific template. If anything is shared between pages, like sometimes you might use the same Carousel or the same section of posts from a custom post type, extract that away to another template file and call it on both pages with get_template_part().

If your homepage is different, then you have to decide how different, if you want to set up some conditionals in the header and footer files and keep them all centralized, or set up a new base-front-page.php and call a different templates/header.php and templates/footer.php files.

The DRY principle isn’t a Roots thing, it’s just a good coding practice. If at any time you copy and paste something within your project and don’t change anything, there’s a good chance you could code it better.

Thanks Kalen,

What you say really makes a lot of sense. I think I’ve been overly concerned with trying to do it a specific way and losing focus on what I’m actually trying to achieve.

I’ve been re-evaluating the content, and the layouts are so specific that I won’t even be using the <?php the_content(); ?> tag. Everything in between the header and footer will be Custom Field content.

In this case I think it would be easier to simply have a page-*.php for each of my unique pages, and then add all of my content inside those.

This allows me to have control over the header and footer and not worry about all the sub templates inside the templates folder. I can see how they are useful if you have content that is more generic.

Thanks again

When I’m developing I also try to plan ahead. I also use a lot of custom fields, but I try to keep them as un-specific and re-usable as possible. That way as well, any of the same or similar sections that can be laid out generically in your code can be re-used and extracted to another .php file to be reused.