|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Graveir Smarty n00b
Joined: 16 Oct 2005 Posts: 1
|
Posted: Sun Oct 16, 2005 8:32 am Post subject: Zmiana liczby na walutę. |
|
|
Hej,
mam taki problem, chciałbym aby smarty zmieniały mi liczbę xxxxx na walutę xxx,xx. W dokumentacji nie mogę tego znaleźć. Może już ktoś z was to robił i od razu by napisał.
Z góry dzięki. |
|
Back to top |
|
SzubertX Smarty Rookie
Joined: 27 Sep 2005 Posts: 8 Location: Poland
|
Posted: Tue Oct 18, 2005 3:08 am Post subject: |
|
|
W samych Smarty czegoś takiego się nie znajdzie... Ale przecież bez najmniejszego problemu można napisać własny modyfikator który się to zrobi (np. poprzez preg_replace), to zajmuje kilka sekund
Proszę, oto byłby taki modyfikator:
[php:1:5fc6f3de4f]
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty waluta modifier plugin
*
* File: modifier.waluta.php
* Type: modifier<br>
* Name: waluta<br>
* Purpose: zmiana kwoty na zmiennoprzecinkowa
*
* @param string
* @return string
*/
function smarty_modifier_waluta($string)
{
return preg_replace ('/(\d+)(\d{2})/', '\1,\2', $string);
}
/* vim: set expandtab: */
?>
[/php:1:5fc6f3de4f]
Wrzuć go do katalogu pluginów Smarty (smarty\plugins) i używaj w samym szablonie Smarty już jako {$cena|waluta} |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|