Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
2 posts Page 1 of 1
If you parse price_lists or CSV to update prices, you might encounter currency symbols besides, i.e. 3$ or $3. Your editable is to be filled only with '3' without symbols.

Well, such a trimming can be done with Couch hack (works only with symbols AFTER the number)
Code: Select all
<cms:number_format '3$' />
=> 3.00


Hope this helps to save some loops.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Hi, trendoman. We could also accomplish this by applying PHP's trim() function by way of a custom tag. The string you want to trim should be the first parameter, currency symbols to be removed are supplied in the second parameter. Of course, you could also use this tag to trim away any other characters you choose.
Code: Select all
<cms:trim_characters "$130.00" "$¥€£¢₡៛₴₱"/>

Additionally, you could use the number_format tag to control the number of decimal places returned.
Code: Select all
<cms:number_format "<cms:trim_characters "£30" "$¥€£¢₡៛₴₱"/>"/>
would return "30.00".

Code: Select all
class TrimCharacters{   
    function trim_characters( $params, $node ){
        global $FUNCS, $CTX;
        if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
        return trim( $params[0]['rhs'], $params[1]['rhs'] );
        }
    }
$FUNCS->register_tag( 'trim_characters', array('TrimCharacters', 'trim_characters') );
2 posts Page 1 of 1