[TYPO3-project-formidable] New Revision 162

Manuel Rego Casasnovas mrego at igalia.com
Wed Jan 16 10:57:49 CET 2008


Hello,

Jerome Schneider escribió:
> * Added lexing mecanism for use inside templates; now one can ask in the 
> template:
>
> 	{myrdtname.label.upper().wrap("<h2>|</h2>")}
>
> List of methods usable in template( as of rev162)
>
> 	nl2br() : converts new lines to <br />
> 	upper() : upper case
> 	lower() : lower case
> 	help()  : prints a simple debug of passed var
> 	debug() : prints a full debug of passed var
> 	concat(mixed var) : ...
> 	wrap(string sWrap) : ...
> 	implode(string sSeparator) : ...
>   

I like a lot this new feature.

I've developed a new method "short". An example:
{myrdtname.short("5")}

If the value for "myrdtname" is "GOOD MORNING", result will be: "GOOD ..."

You could use a second optional param to decide the string to use as
suffix. For example:
{myrdtname.short("7", ".")}
It'll return: "GOOD MO."

For me this function is very useful to create abbreviations or  truncate
long fields.

I send a patch attached to add this new method.
Index: api/class.tx_ameosformidable.php
===================================================================
--- api/class.tx_ameosformidable.php    (revisión: 163)
+++ api/class.tx_ameosformidable.php    (copia de trabajo)
@@ -2401,6 +2401,14 @@
                 return "";
                 break;
             }
+                        case "short": {
+                                $suffix = ($aParams[1]) ? $aParams[1] :
'...';
+                                $string =
tx_ameosformidable::templateDataAsString($mData);
+                                if (is_numeric($aParams[0]) &&
($aParams[0] > 0) && (strlen($string) > $aParams[0])) {
+                                        return substr($string, 0,
$aParams[0]) . $suffix;
+                                }
+                                return $mData;
+                        }
         }
 
         return $mData;


Best regards,
   Rego


-- 
Manuel Rego Casasnovas
Computer Science Engineer
mailto:mrego at igalia.com
Tel: +34 986 10 76 10
Fax: +34 981 91 39 49
Igalia - http://www.igalia.com


More information about the TYPO3-project-formidable mailing list