-
So you need to have an element (as an example, a background, logo, module border etc.) to look different on your Home page and Contact page compared to the rest of your site pages.
We can use a
[JOOMLA-ROOT]/templates/rt_templateName/custom/scss/custom.scss
combined with a page class suffix to accomplish this.
The page class suffix is something that you can add to your menu pages to truly create unique styling for individual content pages. With a page class suffix defined, every single content page could have it's own unique style. For example you could have a custom SCSS background image/colour; font colour/type/size; link colour/typo/size/ or custom typography for that page. The possibilities are almost endless, the only limiting factor is what you can add to a content page. Therefore, anything that you insert into a content page, whether that be an image, some text, a table or a list, it can be styled with a page class suffix in combination with your user created custom style-sheet.
This is a flow diagram of how this feature works:
Home page .........---> page class suffix (outline-24).... ───┐...........................................................┌ Home page
.........................................................................................................├ rt_templateName-custom.scss ┤
Contact Us page ---> page class suffix (outline-28).... ───┘...........................................................└ Contact Us page
In this example we started with a Page Title appearing for the respective menu page. Both Titles are styled identically because of the templates default CSS values.
However by applying a page class suffix to each Menu Page, which also affects the Outline assigned to that page, and incorporating those suffixes into our Custom SCSS file our CSS coding will generate different looks for those Page Titles in our two example pages.
For this guide the "Home page" will be menu item "ID #101" and the corresponding assigned template is denoted as "Outline 24". Using an Inspection Tool like
Chrome Developer Tools
when you inspect the <body> class you will see these represented as class names "itemid-101 outline-24" respectively.
The other page will be the "Contact page" having menu item "ID #36" and the corresponding assigned template is denoted as "Outline 28". When you inspect the <body> class you will see these represented as class names "itemid-36 outline-28" respectively.
If you are aware of the Module Class suffix, this is just the MainBody equivalent. The page class suffix is not delimited by content items, it basically influences anything that is rendered in the MainBody body area. Examples would be:
- All content items, whether that be dynamic or static such as the Example FAQs.
- All front end components that are rendered into the MainBody such as the Login module.
There are two methods to define a page class suffix:
METHOD 1:
MANUAL - In your Template Manager ->
Admin -> Menus -> Main Menu -> a Menu page item (e.g. Home) -> Page Display Options -> Page Class -> some-class-name i.e. "outline-24" or any other valid class name
METHOD 2:
AUTOMATIC -
Admin -> Extensions -> Templates -> rt_templateName - Home -> look in the ID column to get the ID# for that template(outline) -> which shows "24"
The latter is my preferred method. So my page class suffix class name for the "Home page" would then be
outline-24" and for the Outline representing the "Contact page" it would show the ID as "28" so my page class suffix class name for the "Contact page" would then be
outline-28"
The
<body> "parent" element contains all the "child" contents of an HTML document, such as DIVS, text, hyperlinks, images, tables, lists, etc. So any class name found inside the
<body> tag will also affect everything on that menu page just as the "body" class name does.
So lets say in your main stylesheet you have this CSS statement:
body h2.title {
color: #000000;
}
So for any menu page that doesn't have an overriding template the "rt_templateName - Default" outline will be used.
So all these menu pages will have a black text colour.
Now we want the "Home" menu page to have a gray text colour and the "Contact" menu page to have a blue text colour.
Using our page class suffix for the "Home" menu page Outline
outline-24 we duplicate the code above so as to be operative ONLY on the "Home" menu page:
.outline-24 h2.title {
color: #DCDCDC;
}
Likewise for the "Contact" menu page Outline
outline-28 we duplicate the code above so as to be operative ONLY on the "Contact" menu page:
.outline-28 h2.title {
color: #1A3867;
}
You may have noticed at the beginning I stated in the <body> class you will see menu page class names like "itemid-36 outline-28", which are the menu ID and Outline number respectively.
If you were to use
outline-28 to also represent the "About Us" menu page but wanted to keep the default black coloured text for the "Contact" menu page you would use this instead:
.itemid-36 {
color: #1A3867;
}
This would target any menu page with the ID #36 and as all ID's are unique then only the "Contact" menu page would be affected.
Joomla has more information on this
How to use a Page Class Suffix
Last Edit: 8 years 9 months ago by DanG.
The following users have thanked you: Rob West