-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add class to layout region. #1300
Comments
there's already a Would this be what you need, or are you looking for something more specific? |
Thank you @docwilmot .
|
For example, I am porting bootstrap theme. Right now I need to basically rewrite all available layout templates to add class to specific region. Does it make sense now? |
You mean like You could add a |
I see your point. On another hand, theme developer need to update theme each time when layout template has been changed to support new features. If I boil it down, there is two options:
I have other way to add well class to region:
|
I've added this issue to the Layout Followup Meta at #345. Thanks @Gormartsen for opening this issue. It's come up a couple of times, especially with front-end developers. @wesruv mentioned it when he first started with Backdrop. So the basic reasons why classes are not supported:
However, the first reason is mostly philosophical. There are other legitimate reasons why you may want a class on a region. And if people do want to use classes for layout-purposes... well that may be fine too, even if it breaks our attempt at separating layouts and themes. So to make this possible, we'll need to incorporate some way of indicating which layouts support region classes (as right now, none of them do). I think something like this in the layout .info file may pave the way for this and other abilities:
Similar to how we used to have Anyway, the flag in the .info file would enable the ability to set a class in the UI when a layout supported it. The core layouts should then be updated to support region classes in their template and .info files. |
Want! 😄 My sample use case for why we should have this is: Layouts could have different names for the region, or maybe one layout doesn't have a sidebar, per se. I'd also like to see a way for themes (and maybe layouts) to define custom classes so a site builder could select them from the UI, instead of relying on copy/paste, spelling, etc. But that'd be trickier 😛 |
@wesruv could you explain this a bit please? Trying to get what you mean.
Are we talking about doing this (or similar) after all?
Why this? Why not just make this standard for all layouts? |
Personally, I would love to be able to add class via preprocessor. Then I can add UI to theme-settings to colour regions for specified layouts or all layouts. For example add class "fancy-background" to all layouts that support sidebar. Then enduser can select to add fancy-background to only selected layouts and use them on specified pages. Looks promising to me. |
Thought I'd give this a go; it turned into a full-blown foray into |
Why does the dialog still have "Add block" instead of "Configure [region_name] region" as title? |
...also just noticed that the label for the global layout title type drop-down menu (the one right below the "Edit layout" tab) is "Block title type". Shouldn't that be something like "Page title type" instead? ...in all the screenshots in #934 for example, I see it as "Title type". Some accidental thing with a recent commit perhaps? |
Other than the little snags mentioned above, I dig the direction! I'll try to give the code a whirl too |
Tnx guys! |
Awesome work @docwilmot! You totally took the half-finished work on "region styles" and made it work again! That came from panels in D7 but was never finished. Excellent work! I tried out the PR and ran into a few of the same issues noted above. However, caveats aside, this works! I also love the direction. Just add a child wrapper and keep the entire business of classes out of the layout template files. |
One downside to this approach: People may expect that by adding a class to the "region" that they would be able to use layout-controlling classes, like Twitter Bootstrap's column system. Because this is a wrapper inside the layout region div, these classes won't be able to affect the layout itself. It's both a good and bad thing IMO. With this approach, are we really giving people what they want? |
I took a stab at updating the docs in this latest PR. I removed all mention of I like either option #2 or #3. I don't think we need the system to be swappable here. I've used the heck out of Panels and never needed to swap it, so I'm leaning towards #3. We'd still have the inner wrapper, just no "styles". 👍 |
I'm fine either way, I just don't like carrying around abstracted code if we're not going to be using it in the first place. Personally, I'm still of the opinion that the regions should be themeable, and so I like @docwilmot's original approach best (though the added options in @jenlampton's later version was definitely an improvement as well). I've closed the PR at backdrop/backdrop#1336. Please make a new one when ready. |
Personally I like my approach better 😄. I think the ability to theme the region is a good thing and a template to do so is useful. Also I'm not so excited about an additional wrapper around the region content and that |
In the case of this feature request, "adding a class to a region" means adding a second div tag inside the region for the class to be placed onto. We don't want the region's wrapper tag (or classes on it) to be changed - that might break the layout. If the layout needs to be changed, the layout template is there for that purpose. We already have a tool for that job.
I 100% agree, but that abstracted code came from the port of panels. If it's not needed then we should get rid of it. I just didn't know if that was too much change for 1.x.
We're talking about a single div tag here. If every individual div tag in our output was themeable we'd end up in a huge mess!
Yes, there are a lot of useful things we could add to backdrop, but we need to be careful how many and which ones. These are the kinds of decisions that make Drupal/Backdrop hard for HTML/CSS people to learn. There are already far too many places to change the HTML. We need fewer templates with more variables in them. That means getting rid of template files that provide only a single div tag (and pretty please - not adding new ones?) :) However, if we need that div tag to be customizable then fine, we bury a theme function in there (not a template file?), but something like I'll take a stab at a version with a |
Okay, here's a version with the region styles abstraction removed, but a theme function added. This will satisfy my desire for 1) less abstraction 2) no template files that simply output a div. It does not satisfy my desire to avoid broken UIs. However, since we are allowing HTML to be specified in other UIs in core (and also provide theme devs ways to break those UIs) this is at least consistent :) I'm hoping it will also satisfy @quicksketch's desire for
I'm hoping it will also satisfy @docwilmot's desire for
|
Where is it? |
Sorry about that @docwilmot looks like I was pushing to the old branch. Also your comment:
What HTML elements you recommend here? I'm not a HTML5 expert, but it looked like these were common ones. I'm happy to add/remove others as directed :) |
Looking at this first version of the PR, I think I'd also be okay with this theme function being called even when the extra wrapper element is NOT requested. Would that make more sense? We could do something like this... function renderRegion($region_id, $blocks) {
$style_settings = $this->prepared['regions'][$region_id]['style settings'];
$tag = isset($style_settings['element']) ? $style_settings['element'] : '';
$classes = isset($style_settings['classes']) ? $style_settings['classes'] : '';
return theme('layout_region_inner', array('blocks' => $blocks, 'tag' => $tag, 'classes' => $classes));
} and this function theme_layout_region_inner($variables) {
$tag = $variables['tag'];
$classes = $variables['classes'];
if ($tag != '') {
return '<' . $tag . ' class="' . $classes .'">' . implode('', $variables['blocks']) . '</' . $tag . '>';
}
return implode('', $variables['blocks']);
} @docwilmot this would allow all regions to be overridden in the theme - things could be done like BR's added between each block. More utility - but still sans abstraction. People who don't need this would never know it was there. |
OK I'm warming up to this. Simpler indeed, and not sure anyone would really miss swappable styles.
Personally I think forget the entire choosing a wrapper element business. Its a single inner wrapper; make it a
makes sense. But this is always going to be the single element, I cannot imagine any benefit from having a different from just a plain DIV.
I think I prefer that way as well. Finally, the point raised by @quicksketch
couldnt be address with the Region Styles approach, but now if we're canning that, is this an opportunity to allow this instead? |
I think the point is that we don't want to allow it. Back in the very beginning when @Gormartsen mentioned that in the issue, we quickly mentioned that behavior was not only unsupported but also not recommended (and I'd go further to say it should be actively discouraged). From @quicksketch:
The main reason you choose a layout is for the layout it provides. If you don't like it, choose another layout. (Or, override the layout template in the theme.) Attempting to alter it using CSS classes in the UI is opening a whole can of worms :) I am expecting there to be some sort of layout-builder that will come along in contrib and provide some sort of layout-building utility. I think contrib is a great place for that. If it matures there and we get something core-worthy from it, we can put that in. But let's not start by allowing layouts to be adjusted in core. |
The concept sounds okay to me: Remove region styles but maintain the region theme function. I'm in favor of allowing the user to choose their tag for the wrapper. As with blocks, most of the time a DIV is the right thing, but it's probably a site builder or themer that needs the classes for a purpose and wants as much control of their markup as possible (matching what we've done for blocks and at almost every layer of views). This set of changes (with or without region styles) won't have the ability to add classes to region wrappers, as there isn't a variable there to inject a class into in the first place. But like Jen has said above, we're actively discouraging the modification (or breaking) of a layout. |
I'd say I'm in favor of this too. |
Just pushed @quicksketch 's requested changes to the PR |
The current PR looks great but has a legitimately failing test: backdrop/backdrop#1356. Could you fix it @jenlampton? |
Fixed the failing test. |
I've merged into 1.x for 1.4.0. Thanks @docwilmot and @jenlampton! This has made a problem with our dropbuttons become more obvious. Note the gap between the region title and the dropbutton itself: But we already have an issue for this at #370, so we'll pick up fixing this problem there. |
Add ability to add class to layout via template.php
Right now class hard coded to layout tpl file.
It will help to support different layouts on theme level.
Latest pull request: backdrop/backdrop#1356
The text was updated successfully, but these errors were encountered: