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

If/Then statement to show table

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 06-14-2007, 11:17 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Question If/Then statement to show table

I'm trying to come up with an if/then statement to show search keywords (in a table) when there are keywords entered, if not then it should not show.

In my case it's a table that needs to be shown with the following code:
Code:
<table> <tr> <td valign="top"><img src="{$ImagesDir}/icon.gif" width="15" height="17"></td> <td>{$lng.lbl_related_keywords} <br>{foreach from=$keywords item=keyword}<a href="_search.php?q={$keyword}">{$keyword}</a> {/foreach}<br></td> </tr> </table> [b]

This is what I tried (without success):
Code:
{if $keywords ne ""} <table> <tr> <td valign="top"><img src="{$ImagesDir}/icon.gif" width="15" height="17"></td> <td>{$lng.lbl_related_keywords} <br>{foreach from=$keywords item=keyword}<a href="_search.php?q={$keyword}">{$keyword}</a> {/foreach}<br></td> </tr> </table> {/if}

Can anybody help me with this?

Thanks in advance!
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
Reply With Quote
  #2  
Old 06-15-2007, 06:23 AM
  rogue's Avatar 
rogue rogue is offline
 

X-Adept
  
Join Date: Apr 2007
Location: Loveland, Ohio
Posts: 770
 

Default Re: If/Then statement to show table

try

{if $keywords}

You didn't say what is in the $keywords variable. Array? List? Text? An example of the contents would be nice.
__________________
Richard Williams
Rogue Wave Limited

Initial Inventory Imports
Daily Inventory Updates
Daily Inventory Reports
Drop Ship Support
Order Export to Shipper/Supplier
Shopping Feeds That Work
Programming for X-Cart

richard@roguewavelimited.com
http://www.roguewavelimited.com
Reply With Quote
  #3  
Old 06-15-2007, 10:20 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Default Re: If/Then statement to show table

Quote:
Originally Posted by rogue
try

{if $keywords}

Unfortunately this doesn't work

Quote:
You didn't say what is in the $keywords variable. Array? List? Text? An example of the contents would be nice.
The keywords reffer to the search keywords in X-Cart 4.1.3, so that would be text right?
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
Reply With Quote
  #4  
Old 06-15-2007, 12:06 PM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default Re: If/Then statement to show table

Hi Warwick!

Please, edit the <xcart_dir>/include/search.php script and replace:

PHP Code:
if (!$_inner_search)
    
$smarty->assign("search_prefilled"$search_data["products"]); 

with

PHP Code:
if (!$_inner_search)
    
$smarty->assign("search_prefilled"$search_data["products"]);

    if (!empty(
$search_data["products"]["substring"])) {
        
$keywords explode(" ",$search_data["products"]["substring"]);
        
$keywords func_array_map("trim"$keywords);

        if (
is_array($keywords)) {
            foreach(
$keywords as $i=>$k)
                if (empty(
$k))
                    unset(
$keywords[$i]);
            
$keywords array_values($keywords);
        }
        
$smarty->assign("keywords"$keywords);
    } 

After that you'll be able to use the {$keywords} Smarty variable in your templates.
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #5  
Old 06-16-2007, 02:00 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Default Re: If/Then statement to show table

Thanks Eugene!

I have implemented your modification and tried the following statements then but both don't work (yet); forgive me for being such newbie; I must be doing something very stupid.
Code:
{if $keywords} <table> <tr> <td valign="top"><img src="{$ImagesDir}/keywords_small_icon.gif" width="15" [color=red][b]height="17"></td> <td>{$lng.lbl_related_keywords} <br>{foreach from=$keywords item=keyword}<a href="_search.php?q={$keyword}">{$keyword}</a> {/foreach}<br></td> </tr> </table> {/if}

and

Code:
{if $keywords ne ""} <table> <tr> <td valign="top"><img src="{$ImagesDir}/keywords_small_icon.gif" width="15" height="17"></td> <td>{$lng.lbl_related_keywords} <br>{foreach from=$keywords item=keyword}<a href="_search.php?q={$keyword}">{$keyword}</a> {/foreach}<br></td> </tr> </table> {/if}
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
Reply With Quote
  #6  
Old 06-19-2007, 01:22 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default Re: If/Then statement to show table

Please add the following code to a necessary template(at the very beginning):

Code:
{$keywords|print_r}

then refresh the page(or search for any keywrods), do you see any debug info?
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #7  
Old 06-21-2007, 12:19 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Default Re: If/Then statement to show table

I have implemented the code you mentioned in the product template without any if/then statement and get: balancerailArray
(the 'balancerail' being the product name)
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
Reply With Quote
  #8  
Old 06-21-2007, 01:43 AM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default Re: If/Then statement to show table

try using {if !empty($keywords)}{/if}
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #9  
Old 06-21-2007, 01:54 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Default Re: If/Then statement to show table

Thanks inebriate but this doesn't work either
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
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 07:30 AM.

   

 
X-Cart forums © 2001-2020