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

Using Smarty or PHP in cateogry descriptions to reference language strings

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-01-2009, 08:11 AM
 
thisclicks thisclicks is offline
 

Newbie
  
Join Date: Dec 2006
Posts: 7
 

Default 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}
__________________
-Chad
Reply With Quote
  #2  
Old 10-01-2009, 08:22 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default 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']);
Reply With Quote
  #3  
Old 10-01-2009, 08:27 AM
 
thisclicks thisclicks is offline
 

Newbie
  
Join Date: Dec 2006
Posts: 7
 

Default 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?
__________________
-Chad
Reply With Quote
  #4  
Old 10-01-2009, 08:58 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default 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`}
Reply With Quote
  #5  
Old 10-05-2009, 11:08 AM
 
thisclicks thisclicks is offline
 

Newbie
  
Join Date: Dec 2006
Posts: 7
 

Default 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
__________________
-Chad
Reply With Quote
  #6  
Old 10-06-2009, 01:21 PM
 
thisclicks thisclicks is offline
 

Newbie
  
Join Date: Dec 2006
Posts: 7
 

Default 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!
__________________
-Chad
Reply With Quote
  #7  
Old 10-12-2009, 12:53 PM
 
thisclicks thisclicks is offline
 

Newbie
  
Join Date: Dec 2006
Posts: 7
 

Default 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']);


__________________
-Chad
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:09 PM.

   

 
X-Cart forums © 2001-2020