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/Then statement to show table (https://forum.x-cart.com/showthread.php?t=31842)

Warwick 06-14-2007 11:17 AM

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!

rogue 06-15-2007 06:23 AM

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.

Warwick 06-15-2007 10:20 AM

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?

Ene 06-15-2007 12:06 PM

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.

Warwick 06-16-2007 02:00 AM

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}


Ene 06-19-2007 01:22 AM

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?

Warwick 06-21-2007 12:19 AM

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)

inebriate 06-21-2007 01:43 AM

Re: If/Then statement to show table
 
try using {if !empty($keywords)}{/if}

Warwick 06-21-2007 01:54 AM

Re: If/Then statement to show table
 
Thanks inebriate but this doesn't work either :(


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

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