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

Custom Graphic titles for only SOME of the categories.

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 07-26-2003, 03:24 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default Custom Graphic titles for only SOME of the categories.

Since I have gotten so much good advice from this forum, I decided to pass along a little trick that may be useful to someone else.

This will allow you to add custom titles for certain sections, but if the file does not exist, it simply displays the HTML text as usual.

Lets say that you have a few root categories and a lot of sub-categories. The root categories you would like to have a custome "graphic" title for when you go into that category but you dont really need them for all the 100+ sub categories that you might have.

In other words, your main categories are, say, "Saws", "Drills", and "Wrenches" and you want some fancy graphic to display as the dialog title for these categories and maybe for the Help, Shipping and other sections, but not for any of the others. This is a solution that will allow you to make a custom header for any area of the site based on the $title variable that is passed to dialog.tpl.
-------------------------
First, you have to make a new plugin for Smarty. Create a new file in the Smarty-2.5.0/plugins folder named function.file_exists.php. The contents of this file are:
Code:
<?php /* * Smarty plugin * ------------------------------------------------------------- * File: function.file_exists.php * Type: function * Name: file_exists * Purpose: checks if a file exist * ------------------------------------------------------------- */ function smarty_function_file_exists($params, &$smarty) { extract($params); if (empty($file)) { $smarty->trigger_error("assign: missing 'file' parameter"); return; } return file_exists($file); } ?>

Next, change the code in the dialog.tpl file to:
Code:
{* $Id: dialog.tpl,v 1.14 2002/10/22 10:27:05 olga Exp $ *} <TABLE border=0 cellPadding=2 cellSpacing=0 {$extra}> <TR> <TD height="20" class=DialogTitle background="{$ImagesDir}/dialog_bg.gif" valign=bottom> {* Graphics Code *} {assign var="file" value="$ImagesDir/headers/$title.gif"} {if !file_exists($file) } {$title} {else} [img]{$ImagesDir}/headers/{$title}.gif[/img] {/if} {* End Graphics Code *} </TD> </TR> <TR><TD class=DialogBorder><TABLE border=0 cellPadding=10 cellSpacing=0 width="100%"> <TR><TD class=DialogBox>{$content} </TD></TR> </TABLE></TD></TR> </TABLE>

Now, make a new directory in your skin1/images directory named headers. This is to house all the new graphics for the dialog headers and keep them seperate from your other graphics.

To use this just make a new header graphics for what ever section that you want, name it the exact name of the section (eg. Help zone.gif, Privacy statement.gif, Terms & Conditions.gif, FAQ.gif, Saws...), whatever name is used for the $title variable, and copy it to the new skin1/images/headers directory. Take care to examine the file name for the graphic after you FTP it over. You may need to replace some "_" characters with spaces, as FTP transfer will sometimes replace spaces in filename with "_". Also, make sure the capitolization is EXACTLY like it is in the variable.

The best thing about this is that it will allow the graphic titles but you do not have to create them for the entire Admin section either. If the graphic does not exist, it just displays text as usual.
I hope all this makes sense....

{* This is for Verison 3.4.x - I have not tried it on older versions *}
Reply With Quote
  #2  
Old 07-26-2003, 06:15 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

This is great. Thank you for sharing it.

Maybe we should ask them mods to move this to "Custom Templates".

Reply With Quote
  #3  
Old 07-26-2003, 06:29 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

done
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #4  
Old 04-21-2004, 08:23 AM
 
cmtrade cmtrade is offline
 

Advanced Member
  
Join Date: Dec 2003
Location: Florida
Posts: 30
 

Default

Problems...

I tried it myself, only in another variation...

Instead of using it on the categories, I tried using it on the subcategories (subcategories.tpl).
I succeeded in making it work manually (by inputting a whole specific file name), but when I tried to make it work automatically it still showed me the subcategories as text.

After analyzing it bit by bit, I came to the conclusion that it doesn't even check if the file exists. To make my point stronger, I deleted the file "function.file_exists.php" from the plugins directory and I didn't get any error (although the template had the reference to that function).
This probably means, the template doesn't refer to the right file.

Anyway, here's my code, hope that anyone can help:

Code:
{* $Id: subcategories.tpl,v 1.34 2003/10/06 10:04:00 svowl Exp $ *} { include file="location.tpl" } {if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"} {include file="modules/Bestsellers/bestsellers.tpl"} {/if} { include file="customer/main/navigation.tpl" } {if ($navigation_page eq "")||($navigation_page eq "1")}{$current_category.description|regex_replace:"/[\n]/":" "} {/if} {capture name=dialog} {assign var="tmp" value="0"} {section name=cat_num loop=$subcategories} {if $subcategories[cat_num].category}{assign var="tmp" value="1"}{/if} {/section} {section name=cat_num loop=$subcategories} { if %cat_num.first% } {if $tmp} [img]{if $current_category.icon_url}{$current_category.icon_url}{else}{$xcart_web_dir}/icon.php?categoryid={$cat}{/if}[/img] {/if} <table border=0 cellspacing=5> {/if} <tr><td align=left nowrap width=95%> <a href="home.php?cat={ $subcategories[cat_num].categoryid }"><font class="ItemsList"> {assign var="file" value="http://www.nnn.co.il/skin1/images/headers/$subcategories[cat_num].category_name|escape.gif"} {if file_check($file)} [img]http://www.nnn.co.il/skin1/images/headers/{$subcategories[cat_num].category_name|escape}.gif[/img] {else} {$subcategories[cat_num].category_name|escape} {/if} </font></a> </td> <td align=right nowrap><font class=Text> {if $config.Appearance.count_products eq "Y"} {if $subcategories[cat_num].product_count} { $subcategories[cat_num].product_count } {$lng.lbl_products} {elseif $subcategories[cat_num].subcategory_count} { $subcategories[cat_num].subcategory_count } {$lng.lbl_categories|lower} {/if} {/if} </font></td> </tr> { if %cat_num.last% } </table> {/if} {/section} {if $tmp and $products ne "" } <br clear=_all><hr size=1 noshade> {/if} {include file="customer/main/products.tpl" products=$products} {if $products eq "" and $tmp eq "0"} {$lng.txt_no_products_in_cat} {/if} {/capture} {include file="dialog.tpl" title=$current_category.category_name|regex_replace:"/.*\//":"" content=$smarty.capture.dialog extra="width=100%"} {if $products eq ""} {if $f_products ne ""} {include file="customer/main/featured.tpl"} {/if} {/if} { include file="customer/main/navigation.tpl" }

Thanks,
Dan.
Reply With Quote
  #5  
Old 05-02-2004, 07:52 PM
  daddyroy's Avatar 
daddyroy daddyroy is offline
 

Member
  
Join Date: Apr 2004
Location: Tallahassee, FL
Posts: 19
 

Default Nice!!!

Works Great!!!
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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:16 AM.

   

 
X-Cart forums © 2001-2020