Jump to content

Javascript embedded in .tpl templates


Guest jeromas

Recommended Posts

Guest jeromas

I'm trying to add a javascript dropdown menu in place of the category links that are generated by CubeCart; for me, it is a neater way to organize my categories since I have over 30 at this point, and will probably be adding more.

The javascript I am using for this dropdown menu is included in the head of the index page (skins/Legend/styleTemplates/global/index.tpl) though I think it could go in the js/javascript.js file too.

I have used this dropdown menu on another site (www.genomex.com), and it works just fine. I've compared the syntax in case I added an extra space or something along the way, but they appear to both be syntactically the same.

Basically the way I will be calling the dropdown menu is in the following way.

(1) Add a line like this to the categories.inc.php file:

$box_content->assign("JAVASCRIPT_MENU2",'onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this,event,menu2,\'150px\')" onMouseout="delayhidemenu()"');

(2) In the categories.tpl file, I have code like this:

<li><a href="index.php" {JAVASCRIPT_MENU2}>Atari</a></li>

(3) The code that is produced on the page when I view the html source is as follows:

<li><a href="index.php" java script:onClick="return clickreturnvalue()" java script:onMouseover="dropdownmenu(this,event,menu2,'150px')" java script:onMouseout="delayhidemenu()">Atari</a></li>

Update: I figured it out...I was missing the 'language=javascript' in the script tag. If anyone is interested in how to add a dropdown menu instead of the links that CubeCart generates, please let me know by PM or post here. If enough people get interested, I'll generate a little tutorial.

Link to comment
Share on other sites

  • 2 weeks later...

Guest tbladecki

This makes two I would be intrested in it as well I am trying to figure how I can change the state box in the "registeration" area to a drop down similar to the countries...

Link to comment
Share on other sites

This is what I did for categories using the Legend skin when an MSIE browser is detected. First make a file called 'categories_basic.tpl' with the following code (note you'll probably need to change the class 'tradetext1' to something else depending on the look you want):

<!-- BEGIN: categories -->

<div class="boxTitleLeft">{LANG_CATEGORY_TITLE}</div>

<div class="boxContentLeft">

<table><tr><td class="tradetext1" style="padding-top: 3px;" align="center"><a href="index.php" class="txtDefault">{LANG_HOME}</a><br />or</td></tr>

<tr><td style="padding-bottom: 3px;" align="center"><font class="tradetext1">Shop By Category:</font></td></tr>

<tr><td>{FORM_TOP}

{FORM_MIDDLE}

{FORM_BOTTOM}</td></tr>

</table>

</div>

<!-- END: categories -->

Upload this file to /skins/legend/styletemplates/boxes

Next, you need to modify your categories.inc.php page -- here is the entirety of the code I have on that page (note the dropdown menu will only display if the user agent is set as MSIE - you can change this behaviour if you want)

<?php

/*

+--------------------------------------------------------------------------

| CubeCart v3.0.2

| ========================================

| by Alistair Brookbanks

| CubeCart is a Trade Mark of Devellion Limited

| © 2005 Devellion Limited

| Devellion Limited,

| Westfield Lodge,

| Westland Green,

| Little Hadham,

| Nr Ware, HERTS.

| SG11 2AL

| UNITED KINGDOM

| http://www.devellion.com

| UK Private Limited Company No. 5323904

| ========================================

| Web: http://www.cubecart.com

| Date: Friday, 12 August 2005

| Email: info (at) cubecart (dot) com

| License Type: CubeCart is NOT Open Source Software and Limitations Apply

| Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

| categories.inc.php

| ========================================

| Categories Box

+--------------------------------------------------------------------------

*/

if(!isset($config)){

echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";

exit;

}

if(isset($_POST['categoryview']) && !empty($_POST['categoryview'])){

header("Location: {$_POST['categoryview']}");

}

if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') === FALSE){

// query database

$results = $db->select("SELECT cat_id FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_father_id = 0");

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/categories.tpl");

$box_content->assign("LANG_CATEGORY_TITLE",$lang['front']['boxes']['shop_by_cat']);

$box_content->assign("LANG_HOME",$lang['front']['boxes']['homepage']);

// loop results

if($results == TRUE){

for ($i=0; $i<count($results); $i++)

{

$cat_id = $results[$i]['cat_id'];

$sum = $db->select("SELECT count(*) as avaproducts FROM ".$glob['dbprefix']."CubeCart_inventory WHERE stock_level > 0 AND cat_id = '$cat_id' ORDER by cat_id");

//echo "SELECT count(*) as avaproducts FROM ".$glob['dbprefix']."CubeCart_inventory WHERE stock_level > 0 AND cat_id = '$cat_id'";

$box_content->assign("AVAPRODUCTS".$cat_id,"<font color=\"#aaaaaa\">(".$sum['0']['avaproducts'].")</font>");

} // end for loop

}

$box_content->parse("categories.li");

// if($config['saleMode']>0){

// $box_content->assign("LANG_SALE_ITEMS",$lang['front']['boxes']['sale_items']);

// $box_content->parse("categories.sale");

// }

$box_content->parse("categories");

$box_content = $box_content->text("categories");

}

else{

$results = $db->select("SELECT cat_id, cat_name FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_father_id = 0 ORDER BY cat_name ASC");

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/categories_basic.tpl");

$form_middle = '';

$box_content->assign("LANG_CATEGORY_TITLE",$lang['front']['boxes']['shop_by_cat']);

$box_content->assign("LANG_HOME",$lang['front']['boxes']['homepage']);

$box_content->assign("FORM_TOP",'<form action="index.php" method="POST"><select name="categoryview" class="textbox" onChange="location=this.options[this.selectedIndex].value;">');

$form_middle .= "<option value=\"index.php\">Choose A Category</option>";

for ($i=0; $i<count($results); $i++)

{

if($results[$i]['cat_name'] == 'Nintendo Entertainment System'){

$form_middle .= "<option value=\"http://www.gaminggraveyard.com/index.php?act=viewCat&catId={$results[$i]['cat_id']}\">NES</option>";

}

else{

$form_middle .= "<option value=\"http://www.gaminggraveyard.com/index.php?act=viewCat&catId={$results[$i]['cat_id']}\">{$results[$i]['cat_name']}</option>";

}

}

$box_content->assign("FORM_MIDDLE",$form_middle);

$box_content->assign("FORM_BOTTOM",'</select><br /><br /><center><input type="submit" class="submit" value="Go!" /></center></form>');

$box_content->parse("categories");

$box_content = $box_content->text("categories");

}

?>

Don't forget to change the URLs to your own and any other site-specific information. Upload the modded categories.inc.php file to /includes/boxes, backing up your original, and see how it looks.

I did this on the fly (I'm otherwise engaged tonight), so if you have problems with it, post here and I'll check back later. Anyways, the same principles should apply to any CubeCart 3.0+ box

J

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...