Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

if/else for a specific category in the <head> section?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 07-24-2007, 12:07 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default if/else for a specific category in the <head> section?

I am well aware of how to use the {if $cat eq "1"} do this {/if} from within a template -- if the template is in the body of the html.

I a STUMPED! however of how to use the {if $cat == "1"} to load a category specific style sheet or javascript.

FOR EXAMPLE:

in /skin1/customer/home.tpl

just before the </head>

I want to insert a stylesheet unique to category 19, and a link to a javascript file, only if a specific product or category is present.

I tried this:
Code:
{if $cat eq "19" } <link rel="stylesheet" href="{$SkinDir}/directoryname/stylesheet19.css" /> {literal}<script language="JavaScript" src="{$SkinDir}/directoryname/category19js.js" type="text/javascript"> </script>{/literal} {/if} </head>

Hmm... didnt work.

I tried {if $cat == '19'} - and a bunch of variations.

IS THE PROBLEM that the <head> loads before the <body> and until the body loads, there is no way to trap for the category?

DO I HAVE TO load javascript and css links in the <head> - or can I put a css link in the body of a page? I have never done this...

Experts???

Thanks,

Jeremy

UPDATE:

It turns out the "category" I want to do this with is actually a sub-cat, if I use the if/else for the PARENT category, it works, but if I use {if $cat eq "z"} [and z=the number of the subcategory] then it fails to work.

Hmm... I tried $subcat eq "z" -- no good. Any ideas how to do this with the subcat # ??? Thanks!
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #2  
Old 07-24-2007, 05:57 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default Re: if/else for a specific category in the <head> section?

If it's for the current category, you should be able to use {if $current_category.categoryid eq "X"}Include{/if}.

Otherwise if you post specific category urls and ids I'll see if I can help you.
Reply With Quote
  #3  
Old 07-24-2007, 07:39 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: if/else for a specific category in the <head> section?

Hi Jon,

Unfortunately, made no diff.

Same results.

{if $current_category.categoryid eq "9"}
--(which is the "parent" category) -- works perfectly

{if $current_category.categoryid eq "19"}
--(which is the "child" subcategory) -- does not

Hmm.

The url is my domain.com/makeup/pretty-n-polished.html

(this is category 19)

Does CDSEO help or hinder such a category call in smarty?

Come to think of it, I have a bit of code to redirect a single category to the product...

http://forum.x-cart.com/showthread.php?t=23339

Maybe this is getting in the way?
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #4  
Old 07-24-2007, 09:34 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default Re: if/else for a specific category in the <head> section?

You're correct, the single product in a category redirect is causing your problem here.

http://www.mommymakeup.com/makeup/pretty-n-polished.html <- This is a product page.

Use:

{if $product.categoryid eq "X}Include{/if}

or

{if $product.productid eq "X}Include{/if}
Reply With Quote
  #5  
Old 07-25-2007, 05:53 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: if/else for a specific category in the <head> section?

Jon,

{if $product.productid eq "X}Include{/if}

worked great. thank you.

I guess the "single product in a category" code kills the subcat relationship -- so I must use a direct product var.

Now a question to anyone reading this far:

Does having a bunch of these if/elses in home.tpl slow my site down?

{if $product.productid eq "1" || $product.productid eq "11" || $product.productid eq "21"}

How much overhead does smarty use when parsing a list of if/else(s) ?

Should I be concerned? I see lists of if/elses in home_main.tpl and other templates... does this take a bite out of performance?

Thanks!

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:01 AM.

   

 
X-Cart forums © 2001-2020