Forums / Developer / Sub string

Sub string

Author Message

David Santiso

Wednesday 16 March 2011 1:23:40 pm

Hi,

I want to show a part of string like the "substr" php function.

How can I do it?

Thanks,

David

Theodoros Papageorgiou

Wednesday 16 March 2011 3:19:44 pm

Hi,

You can use the extract template operator.

For other options have a look at
http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators
(Scroll down to the String operators)

WEBWiZ
Web Development
http://www.webwiz.gr

David Santiso

Friday 18 March 2011 2:11:13 pm

Yes, but in my case I'm trying to extract part of a string obtained from an attribute of "text area" datatype.

If I put:

{set-block variable=$attribute}
  {attribute_view_gui attribute=$var.data_map.description}
{/set-block}
...
{$attribute|extract( 0, 10) }

There is no result, but out of position the rest of the template imformation.

If I put a smaller length:

...
{$attribute|extract( 0, 3) }

Shows strange characters as "> !".

Theodoros Papageorgiou

Saturday 19 March 2011 1:08:41 pm

Using the attribute_view_gui function you also iclude the formated output of the attribute level template in your string. Since you need the raw output of a Text block datatype you could try something like this:

{$var.data_map.description.content|extract(0,10)}

However, if you are using an XML block datatype you also need output.output_text and strip the tags from your text with the PHP strip_tags operator.

WEBWiZ
Web Development
http://www.webwiz.gr

David Santiso

Sunday 20 March 2011 6:51:58 am

Thaks,