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)
-   -   combining truncate and replace (https://forum.x-cart.com/showthread.php?t=58604)

keystone 03-24-2011 10:43 AM

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?

keystone 03-24-2011 11:24 AM

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.

keystone 03-28-2011 10:28 AM

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

qualiteam 03-29-2011 06:26 AM

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}


All times are GMT -8. The time now is 12:55 PM.

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