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

combining truncate and replace

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-24-2011, 10:43 AM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default combining truncate and replace

I am trying to remove the commas from my meta_keywords variable and replace them with nothing "" in this line

Code:
{$_meta_keywords|truncate:"130":"":false|escape}

and truncate it to the 5th word. (I haven't started on the "5th word" part) This is what I was trying without much success along with a couple of other variations.

Code:
{$_meta_keywords|replace:",":""|truncate:"130":"":false|escape}

Anyone know how to do that?
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #2  
Old 03-24-2011, 11:24 AM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default Re: combining truncate and replace

I got replacing the commas worked out and truncating to the 100th character while keeping the last full word intact. Looks like this now.

Code:
{$_meta_keywords|truncate:"100":"":false|replace:',':''|escape}

using this to create unique alt tags for my logo image on each page. The alt tag will match with the first few words of my meta_keywords on each page.
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #3  
Old 03-28-2011, 10:28 AM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default Re: combining truncate and replace

I was wondering if anyone knows if it is possible to truncate a string but to do it at the first "," instead of at a certain number of characters? For example

scented candles, votives, candle holders

would be shown only as

scented candles

thanks
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #4  
Old 03-29-2011, 06:26 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: combining truncate and replace

You can create a custom Smarty modifier, e.g. like this:

1. create a new Smarty modifier plugin -> "include/templater/plugins/modifier.mymodifier.php" with the following content:
PHP Code:
<?php 

if (!defined('XCART_START')) { header("Location: ../../../"); die("Access denied"); } 

function 
smarty_modifier_mymodifier($param) {
   
$param explode(','$param);
   
$param = isset($param[0]) ? $param[0] : $param;
   return 
$param;


?>

2. add further use something like:

{$_meta_keywords|mymodifier}
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
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:13 PM.

   

 
X-Cart forums © 2001-2020