Understanding the roots' logic

Hi,

I just wrote in the past month to understand the logic behind Roots. I don’t know of if I miss something, but I have some difficult to understand why this structure is best then the Wrapperless system.

I ask this because if I would to have a custom template, every time I have to duplicate the base.php and postpend the name of the template (base-[template name].php). Normally, I would duplicate only the interested file (i.e. page.php -> about.php or page.php -> contact.php). Here, I have to duplicate the template file and the base-*.php with the postponed name, so 2 files…

I miss the advantage of the wrapper structure, so I ask to you because I wish to understand how it work.

I hope that someone help me to understand.

Thanks

If you find that you need to duplicate the base-XXX.php more than two or three times then you may be misusing that workflow. It is more efficient to change the contents of base.php to reflect the base you need for the maximum number of templates and only create variations for templates that diverge from that.

So, if you have 10 templates total and 8 of those templates use the same custom base-XXX.php markup, it is more efficient to move the contents of those custom base files into the default base.php and instead create a new base-XXX.php for the two remaining temaplates because those are the exceptions to your rules.

Does that make more sense?

1 Like

I think to have understood. Thanks
Just to be sure: I do my customization on templates inside the template’s directory and/or all new template created by me, right?

If yes, in what case I should to create a new base-*.php? Can you make me an example?

Correct, you do not need to create a new base-XXX.php for every template. In fact some of my projects just use the one base.php as my base.

Have you looked at the docs? This stuff is pretty well covered. If you open base.php you should be able to figure out the areas of your pages its markup corresponds to and make changes as needed.

The quickest example I can think of is a template that has multiple sections where each section needs to have its own full screen background or background color. Something like this.

1 Like

Understood.
For example, I created a base-home.php for to be able to create a fullscreen slider section, unlike the others page, correct?

You don’t need a new base.php file to do that, see:

http://discourse.roots.io/t/full-width-home-image-full-width-sections/485

Most of the solutions in @benword’s link are a little too hacky for me. They either involve conditionals which you need to remember to close or they could end up becoming very long conditionals as your project grows.

You could also take @Foxaii’s route and use LESS/CSS to change the .container width, but then you’ll end up having to add significantly more markup if the content following the fullscreen slider needs to be constrained responsively.

I know the prevailing wisdom among Roots devs is to limit the number of custom base templates, but I feel very strongly that your specific case—a fullscreen slider section—is a perfect candidate for a custom base template. You will need to add a div.container for the content that follows your slideshow, but I think overall it’s a smoother, more straightforward, and more flexible strategy.

1 Like

Thanks. I have seen the @Foxaii post that talk about to use the sidebar class to determine if is fullwith or not.
Can I have an example?