The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
CSS for Template ID verus Page ID
When editing templates based on page ID (.page10 as example), only that specific page item is affected. Other pages that share the same templates are not.
Is there a quick and easy way to hit a specific template instead, via CSS? |
#2
|
||||
|
||||
You can with javascript/jquery. There is a javascript object on every page called pageData. The pagetemplateid is in that array. You can find the pagetemplate id by right click, view source, find (Ctrl-f) pagetemplateid. So if you do something like this for pagetemplate 93
Code:
$(document).ready(function(){if (pageData['pagetemplateid']== '93'); $('body').css('background', 'red'); }); |
#3
|
|||
|
|||
Hi,
Thanks for replying. Are java queries like this able to be executed from inside additional.css? I added the code below, but don't see the equivalent result with avoiding the templateid check. Code:
$(document).ready(function(){if (pageData['pagetemplateid']== '4'); $('#outer-wrapper').css( 'background-color', 'red'); }); Code:
.css('x','y') Code:
.css{('x','y'),('z','a')} |
#4
|
||||
|
||||
No. additional.css is just for css. Easiest way to add the script is in an ad module. Open site-builder, drag the ad module down on the page, paste the code above in the ad module editor enclosed in script tags. You can also add the code via template hook if you want it on every page.
Code:
<script>$(document).ready(function(){if (pageData['pagetemplateid']== '93'); $('body').css('background', 'red'); }); </script> And on your second question, you almost had it in example two. The braces go between the parenthesis. Code:
.css({ "background-color": "yellow", "font-weight": "bolder" }) |
Благодарность от: | ||
David Karol |
#5
|
||||
|
||||
It would be easier for the script to simply add a css class in the body tag based on the template id. Then use that class to style in css whatever elements on the page you want to style.
Code:
<script>$(document).ready(function(){ $('body').addClass('pagetemplate-', pageData['pagetemplateid']); }); </script> Code:
.pagetemplateid-93 #outer-wrapper { background-color: red; } |
2 благодарности(ей) от: | ||
David Karol, Replicant |
#6
|
|||
|
|||
I added below code to a hook, run from header_head.
Code:
<script type="text/javascript"> $(document).ready(function() { $('body').addClass('pagetemplate-', pageData['pagetemplateid']); }); </script> What does work is amending header template, line 146 as below: Code:
<body id="vb-page-body" class="l-desktop page{vb:var page.pageid} vb-page view-mode{vb:raw isLoggedout}{vb:var state} pagetemplateid{vb:var page.pagetemplateid}" {vb:schema {vb:raw bodySchema}} {vb:raw group_data_attr}> |
#7
|
||||
|
||||
Because jQuery is not available at that point yet.
Use header_after_body_begin hook location with this script. Code:
<script type="text/javascript"> document.body.className += ' pagetemplate-', pageData['pagetemplateid']; </script> |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|