AutoNav template: why is custom template affecting non-custom templates?
Permalink
I created a custom template in ~/blocks/autonav/templates/header_nav
In there, I put a view.php and css/view.css
I then selected "custom template" for that menu and chose "header_nav"
The content installed by default includes a sidebar stack menu which does not have a custom template... and yet that menu is pulling the same style. WTF is going on here?
In there, I put a view.php and css/view.css
I then selected "custom template" for that menu and chose "header_nav"
The content installed by default includes a sidebar stack menu which does not have a custom template... and yet that menu is pulling the same style. WTF is going on here?
![](/files/avatars/none.gif)
LOL, every autnav I add anywhere has this custom template applied even though I am not choosing the custom template and even though the custom template is only found in ~/blocks/autonav/templates/header_nav.
Further confirmation: if I delete the css file from the custom template's directory, all the menus get screwed up. That means every menu is pulling from the custom template even if they shouldn't be.
have you tried giving other nav bars another template and see what happens; if only this one will use that template and the other ones will use the first template?
Yes, if I give the other autonavs a specific template other than the one I just installed, they will grab that one. But, if I just leave it as (none selected) then they grab the custom template. It's as if the custom template I just created is the new default for some unknown reason.
That's not normal, right? A custom template shouldn't suddenly become your new default, right?
Alright, figured it out. I am surprised C5 works this way, but it does... Had to add a prefix of the div id before all the CSS styling. Even though the CSS is in a custom template folder which means (in my interpretation, anyway) that it should not be applied to anything else.
So... what that means is the CSS located in blocks/autonav/templates/header_nav/view.css had to have all its styles prepended with #header because that is the div where this particular autonav is placed in.
So... now becomes It's not right, but that's what it came down to.
So... what that means is the CSS located in blocks/autonav/templates/header_nav/view.css had to have all its styles prepended with #header because that is the div where this particular autonav is placed in.
So...
.nav {etc}
#header .nav {etc.}
Well actually it makes sense. Css rules apply to everything in the page that calls for it so any .nav element will follow the rules.
that's not how other custom templates work, is it? I don't recall ever bumping into this issue before in ~3 years of C5 usage.
It's not a matter of how a template works.
Elements in a page are not isolated because they belong to different structural parts of C5. Everything is merged in the page. If you have in your css a class name with some style applied to it, anything in the page with that class name will be targeted as well. The css has no idea that this html comes from this add-on or that one.
That's why there's (almost) always a div with a unique name around blocks, to be able to target them specifically. You should always do that as a rule.
I guess you just got 3 years of pure luck :)
Elements in a page are not isolated because they belong to different structural parts of C5. Everything is merged in the page. If you have in your css a class name with some style applied to it, anything in the page with that class name will be targeted as well. The css has no idea that this html comes from this add-on or that one.
That's why there's (almost) always a div with a unique name around blocks, to be able to target them specifically. You should always do that as a rule.
I guess you just got 3 years of pure luck :)
I think you maybe misunderstood zoinks. He didn't add the rules to the main theme css but to the view.css that belongs to the view.php of the custom template. And as long as this custom template isn't set to a block the rules in it should not matter.
I understand that but as I said, the page doesn't know what loaded the css.
The template was applied to at least one block (the nav bar) so the css was loaded in the page thus made available to the whole page and if any element shares some of the class names targeted by that css then it will be styled accordingly which is why when zoinks modified his css to be more specific (added an id), the problem disappeared.
The template was applied to at least one block (the nav bar) so the css was loaded in the page thus made available to the whole page and if any element shares some of the class names targeted by that css then it will be styled accordingly which is why when zoinks modified his css to be more specific (added an id), the problem disappeared.
Okay, I thought the template wasn't loaded at all. The way you tell it does make sense, absolutely.
The merging makes total sense, I just didn't realize that's what C5 was doing this whole time. I thought it was dynamically loading/creating something special when a custom template was applied.
And I don't recall ever reading that 1 custom template would affect all other instances of the same block type per page. That's one for the documentation, for sure.
And I don't recall ever reading that 1 custom template would affect all other instances of the same block type per page. That's one for the documentation, for sure.
Yeah, definitely lucky I guess. I think just generally because I don't have more than 1 of the same block on a page, usually. For example, the horribly broken galleria add-on was one that I had several custom templates for... but, I never had more than 1 gallery per page.