X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   if/else for a specific category in the <head> section? (https://forum.x-cart.com/showthread.php?t=32768)

carpeperdiem 07-24-2007 12:07 PM

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!

Jon 07-24-2007 05:57 PM

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.

carpeperdiem 07-24-2007 07:39 PM

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?

Jon 07-24-2007 09:34 PM

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}

carpeperdiem 07-25-2007 05:53 AM

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


All times are GMT -8. The time now is 02:42 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.