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)
-   -   Using Smarty or PHP in cateogry descriptions to reference language strings (https://forum.x-cart.com/showthread.php?t=49978)

thisclicks 10-01-2009 08:11 AM

Using Smarty or PHP in cateogry descriptions to reference language strings
 
Hi. I want to be able to include a language referecne in my category descriptions. For example I would like to put "$lng.lbl_my_text" in the description tag.

I've thought of doing this a couple ways but neither work. Does anyone know how I can do this.

Here are the ways I've tried it:

Var only:
PHP Code:

$lng.lbl_my_text 


PHP:
PHP Code:

<?php echo "$lng.lbl_my_text"?>


Smarty:
Code:

{php} echo '$lng.lbl_my_text'; {/php}

Jon 10-01-2009 08:22 AM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
It won't work since smarty tags won't be processed. You'd probably have to set a variable in your text like ##yourvariable## and then in your home.php file use something like:

Code:

if ($current_category['description'] != '')
$current_category['description'] = str_replace('##yourvariable##',func_get_langvar_by_name('lbl_my_text'),$current_category['description']);


thisclicks 10-01-2009 08:27 AM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
Thanks for the info. Would it make the most sense to do this in the PHP file for home.php or should I do this in the TPL files? Probably the home.php.... right?

Jon 10-01-2009 08:58 AM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
Usually best to put any php processing into the php file, but you could do something this in smarty everywhere the description is used in tpl files (i.e. skin1/customer/main/subcategories.tpl}:

{$current_category.description|replace:"##variable ##":`$lng.lbl_my_text`}

thisclicks 10-05-2009 11:08 AM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
Quote:

Originally Posted by Jon
It won't work since smarty tags won't be processed. You'd probably have to set a variable in your text like ##yourvariable## and then in your home.php file use something like:

Code:

if ($current_category['description'] != '')
$current_category['description'] = str_replace('##yourvariable##',func_get_langvar_by_name('lbl_my_text'),$current_category['description']);



Is there a way to make this a little smarter? So I don't have to put an IF statement for each $lng VAR?

Could it somehow evaluate the ##yourvariable## and attached it to $lng.yourvariable ? Would that be some kind of eval function? Thanks for the help.

Thanks,

Chad

thisclicks 10-06-2009 01:21 PM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
Quote:

Originally Posted by thisclicks
Is there a way to make this a little smarter? So I don't have to put an IF statement for each $lng VAR?

Could it somehow evaluate the ##yourvariable## and attached it to $lng.yourvariable ? Would that be some kind of eval function? Thanks for the help.

Thanks,

Chad


Anybody have any ideas on how to do what is described above? Thanks!

thisclicks 10-12-2009 12:53 PM

Re: Using Smarty or PHP in cateogry descriptions to reference language strings
 
I figured it out. It's a bit more dynamic this way. This will work for current_category descriptions that have one var defined in them as ##VAR##. put this in the home.php along with the other smarty assigns. you'll need to change the smarty var reference in your tpl to this new one.

PHP Code:

$cat_desc $current_category['description'];

if (
strpos($cat_desc'##'0)) {
    
    
$cat_lng_str substr($cat_descstrpos($cat_desc'##'0), strpos($cat_desc'##'1));
    
    
$cat_lng_var str_replace("##"""$cat_lng_str);
    
    
$tmp_lng func_get_langvar_by_name("$cat_lng_var");
    
    
$smarty->assign("cat_desc"str_replace($cat_lng_str$tmp_lng$current_category['description']));

} else {

    
$smarty->assign("cat_desc"$current_category['description']);





All times are GMT -8. The time now is 07:59 PM.

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