Reversing the logic of displaying the sidebar

The site I’m currently developing is almost all full width, with only a couple pages requiring a sidebar. As-is I would need to create a template and assign it to the 20 pages that are fullwidth and add that template to the exclusion array in config.php, Is there any harm in reversing the logic in lib\sidebar.php and using the array as an inclusion list for sidebar the instead?

I did a quick test and it worked, just wanted to make sure I wasn’t being shortsighted on this and missing something.

All I did was change public $display = true; on line 18 of sidebar.php to false; and $this->display = false; on line 28 to true, then made the appropriate considerations in the conditional and template arrays.

Another question altogether would be is it bad form for me to not create a template and have my pages set to the default template (page.php)?

There’s nothing wrong with reversing the logic. There are other ways to do it without changing the class but that only matters if you reuse the class elsewhere (for a second sidebar etc). Just reverse where the boolean is returned:

return apply_filters('roots_display_sidebar', !$sidebar_config->display);

If you don’t plan on reusing the class, keep it how you have it already.

You also don’t need to apply page templates to filter the sidebar. You can use any conditional tags (so array('is_page', 42) would filter by page ID matching 42). There are other examples in the docs.

Regarding templates, the fewer and the simpler, the better. Don’t needlessly create page templates and don’t obfuscate the HTML with lots of complex logic (but a little logic is fine if it avoids lots of repetition). If you follow those two rules you should be fine.

Ah, cool, you’re way is easier and less for me to comment and remember what the hell I did. I’m not totally sure I’m going to reverse it, but if I do, I’ll be using that technique. Thanks man.