Share » Forums » Developer » is this operator exists in ez32...

is this operator exists in ez32 template lang ? (was in smarty tmp)

is this operator exists in ez32 template lang ? (was in smarty tmp)

Wednesday 21 May 2003 5:41:02 am - 8 replies

Author Message

Jan Borsodi

Wednesday 21 May 2003 5:47:00 am

No, but if you know some PHP you can very easily create it yourself.
Look at lib/eztemplate/classes/eztemplatephpoperator.php for a very simplistic operator, copying this and creating a new operator shouldn't be too difficult.
There might also be some PHP function which can do the whitespace stripping for you.

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

Selmah Maxim

Wednesday 21 May 2003 7:32:43 am

---------
$tpl->registerOperators( new eZTemplatePHPOperator( array( "upcase" => "strtoupper",
"reverse" => "strrev" ) ) );
------------

nice but where to insert this code ?

what i need maybe not operator , maybe modifier , how to add this function to the template :
{strip}
..
.
.
{/strip}

the php function could be this :

function MakeStrip($str)
{

$match = array();
if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $str, $match))
{
$strip_tags = $match[0];
$strip_tags_modified = preg_replace("!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", '', $strip_tags);
$strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified);
for ($i = 0; $i < count($strip_tags); $i++)
$template_compiled = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s",
preg_replace('![\\$]\d!', '\\\\\\0',$strip_tags_modified[$i]),
$str, 1);
}

$Str = str_replace("}","",$template_compiled);
return str_replace("{","",$Str);
}

from smarty code!

thx.

Bruce Morrison

Wednesday 21 May 2003 9:06:42 pm

I actually wrote something about this the other day in the Contributed documentation :)
http://ez.no/developer/ez_publish_3/documentation/ez_publish_3/terminology_basics/undocumented_template_functions_and_operators/adding_custom_template_operators_eztemplatephpoperator

You could use this to make the php function 'trim' http://www.php.net/manual/en/function.trim.php availiable in templates (trim only removes whitespace from the begining and end of the text)

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Selmah Maxim

Thursday 22 May 2003 12:51:19 am

no need for trim here, i need to remove the all white parts from the template, becoz some times it make error in the template layout!
i.e
<td><img src=....>
</td>

in this case some times u will get white spaces 1x1 pix under the image !

what i wanna do to add this function to ez temp lang :

{strip}
TEMPALTE content
{/strip}

the function above will replace all the white space in the template, not like trim !

any help ?

Bruce Morrison

Thursday 22 May 2003 3:14:02 pm

I've seen this issue as well and have found that the easier way to get around it is to modify the ezimage.tpl template so that it is all one a single line.

The strip function sounds like a good addition. These doesn't appear that there is a php function that will do this directly.

It is possible to add a template function to ezpublish as an extention. Have a look at the ezRSS contributed module. It basically creates a new template operator as an extention. You could use this to add the strip function.

Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Selmah Maxim

Friday 23 May 2003 3:49:35 am

Hi Bruce ..

make ezimage.tpl one line will do nothing !
try to look at this page source, and i had worte above fucntion (from smarty template) will make no white space in source (\t \r) !

i got no idea from Ezrss since is geting an array from new site !

i think how cann`t get the idea of strip, copy the function above and try it, or download smarty and try it !

Bruce Morrison

Friday 23 May 2003 6:47:18 pm

Hi Selmah

>make ezimage.tpl one line will do nothing !

It will, I know because I have done it :) Basically you need to remove all the unnecessary whitespace and all newlines from ezimage.tpl to ensure that you don't end up with extra padding when the image is rendered in a table.

>try to look at this page source, and i had worte above fucntion (from smarty >template) will make no white space in source (\t \r) !

I understand what you are tring to achieve, editing ezimage.tpl is simply one way of doing it.

> i got no idea from Ezrss since is geting an array from new site !

EzRSS is an example of adding a new template operator as an extention. You should be able to use this to add your strip template. Use the framwork in EzRSS but replace the function that gets the info from the other site with your strip function.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Selmah Maxim

Saturday 24 May 2003 12:38:25 am

Hi Bruce ..

Your idea is right, but i need to remove all the spaces from the template :)

i`ll keep trying with ezrss !

thx anyway !

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu