Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Design and Graphics Discussions
  #1  
Old 11-20-2016, 03:33 PM
David Karol David Karol is offline
 
Join Date: Jan 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 11-21-2016, 02:23 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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');
});
It would set the background css attribute red for the body tag. You can use #your-id or .your-class in place of body and change the css attribute to whatever you want to set.
Reply With Quote
  #3  
Old 11-23-2016, 03:13 AM
David Karol David Karol is offline
 
Join Date: Jan 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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');
});
On top of this, should multiple items be allowed in as below:
Code:
.css('x','y')
versus
Code:
.css{('x','y'),('z','a')}
Reply With Quote
  #4  
Old 11-23-2016, 10:17 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"
    })
Reply With Quote
Благодарность от:
David Karol
  #5  
Old 11-24-2016, 12:58 AM
noypiscripter's Avatar
noypiscripter noypiscripter is offline
 
Join Date: Jul 2013
Posts: 468
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Then in CSS:

Code:
.pagetemplateid-93 #outer-wrapper {
    background-color: red;
}
Reply With Quote
2 благодарности(ей) от:
David Karol, Replicant
  #6  
Old 11-24-2016, 11:40 PM
David Karol David Karol is offline
 
Join Date: Jan 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
This results in an browser console error: "Cant find variable $". I tried to enclose everything in (function($)), which led to no more error. With that though, the pagetemplateID never made it into page source.

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}>
Reply With Quote
  #7  
Old 11-25-2016, 09:10 PM
noypiscripter's Avatar
noypiscripter noypiscripter is offline
 
Join Date: Jul 2013
Posts: 468
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:19 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11576 seconds
  • Memory Usage 2,225KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (11)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (3)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete