Opened 12 years ago
Closed 10 years ago
#23470 closed defect (bug) (fixed)
Convert slash to dash and make body class for page templates look better
Reported by: | Caspie | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | Themes | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
If you keep you page templates in a page-templates folder in your theme. Let's we have a template named front-page.php - the template slug written in the postmeta will be page-templates/front-page.php
When generating the classes for the body, get_body_class() will convert the dot to a dash but the slash will be stripped by sanitize_html_class().
So finally we will have a class:
page-template-page-templatesfront-page-php
Isn't it prettier to convert the slash to dash and to have it like:
page-template-page-templates-front-page-php
Attachments (5)
Change History (17)
#2
follow-up:
↓ 3
@
12 years ago
- Cc donutz added
I would like to make a case for fixing it.
First, something like page-template-page-templatesfront-page-php looks quite horrible, not to say buggy or erratic. I wouldn't use such a selector in my stylesheet :)
Second, moving templates to a sub-folder (and thus being forced to reapply them) breaks things as well (css), one expects to have access to the same body class selector, template located in sub-folder or not.
Third, it could be useful to have the sub-folder name as a separate body class, so one could group a bunch of templates and style them all in one go.
I attached a diff file with a possible solution.
#3
in reply to:
↑ 2
@
12 years ago
Replying to donutz:
I would like to make a case for fixing it.
First, something like page-template-page-templatesfront-page-php looks quite horrible, not to say buggy or erratic. I wouldn't use such a selector in my stylesheet :)
Agree.
Second, moving templates to a sub-folder (and thus being forced to reapply them) breaks things as well (css), one expects to have access to the same body class selector, template located in sub-folder or not.
Disagree. When a template is moved to a subfolder, all posts using that page template break. I see no reason why the CSS class shouldn't also change.
Third, it could be useful to have the sub-folder name as a separate body class, so one could group a bunch of templates and style them all in one go.
Clever idea.
#6
@
10 years ago
We won't be able to just change the way we pass on the page template class, too many themes are using the current syntax. We'd have to add the optimized version as an additional class.
I like the idea of having subfolder names as a separate body class, though it makes 23470.2.diff a bit more verbose than I'd like it to be. Using Twenty Fourteen as an example, theme authors could use attribute selectors to make that work too: [class*="page-template-page-templates"]
.
#7
@
10 years ago
- Milestone changed from Awaiting Review to 4.1
For the initial example, the updated patch creates the following output:
page-template
, page-template-page-templates
, page-template-front-page-php
, page-template-page-templatesfront-page-php
.
This happens to address the concern of changing class names when moving page templates in and out of subfolders. To me it's just a more esthetic class name.
#8
@
10 years ago
Would be page-template-page-templates-front-page-php
too much? Can we get rid of appending -php
to the new ones?
#9
@
10 years ago
Updated patch, to avoid the php
suffix in the new classes.
page-template-page-templates-front-page-php
will stay around forever though.
Page templates in subdirs are supported since 3.4, see #11216.
Fixing it could break some themes. :(