IP.Board Tutorials

Theme Tip: Styling specific elements on specific pages

Submitted by tormentor, , Thread ID: 94937

Thread Closed
tormentor
Newbie
Level:
0
Reputation:
0
Posts:
17
Likes:
5
Credits:
2
09-07-2018, 03:05 AM
#1
This applies to both 4.2 and 4.1 versions of IPS.

Occasionally you'll want to style a specific element on a specific page of your community - maybe you want to change how topic titles are shown inside a topic, or do something specific to the styles used in activity streams, without also altering other screens where the same elements are used.

Your first instinct might be to open the template editor and add some custom classnames so you can style them. This would certainly work, but the downside is your template is now customized, so any future IPS4 updates would leave the template out of date. Notideal by any means.

Instead, you can use some helpful attributes that IPS4 adds to thebodyelement, and then build a CSS selector around them. There's four attributes, and they always reference the current page the user is on:


  • data-pageApp- The application key (e.g.core,forums,cmsetc.)
  • data-pageModule- The current module with the application (e.g.pages)
  • data-pageController- The current controller within the module (e.g.topic,pageetc.)
  • data-pageLocation- Eitheradminorfront.

So let's say we want to change how the.ipsPageHeaderelement looks within topic view. Our selector would look like this:



Quote:
body[data-pageapp="forums"][data-pagemodule="forums"][data-pagecontroller="topic"] .ipsPageHeader {
...your styles
}



If you don't want to be that specific, you can just use the attributes you need. For example, if you want to change all.ipsPageHeaderstyles in the Forums app, you'd do:





Quote:
body[data-pageapp="forums"] .ipsPageHeader {

...your styles

}



Tip:If you don't know the correct app/module/controller for the page you're on, you can find out by visiting the page and then viewing the page source. You'll see these attributes in thebodytag near the top.

And as always, be sure you add your CSS tocustom.cssto keep your upgrades easy.

Users browsing this thread: 1 Guest(s)