Checking Length of variable

Author Message

Tony Stark

Monday 21 April 2008 9:58:54 am

Sounds like a noob question (and I am) but if I have the following:

{def $mytext=$this_object.data_map.mydata.content.output.output_text|strip_tags()}

how can I check the length of $mytext and make decisions on it?

i.e. to check if $mytext is greater than 0?

thanks

Tony

Felix Laate

Monday 21 April 2008 11:40:01 am

Hi Tony,

you could use the count_chars-operator:

http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/strings/count_chars

{if gt($mytext|count_chars,'0')}
your code..
{/if}

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Maxime Thomas

Monday 21 April 2008 11:39:15 pm

Or in a prefixed way :

{if $mytext|count()|gt(0)}
...
{/if}

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 01:13:40
Script start
Timing: Jan 19 2025 01:13:40
Module start 'layout'
Timing: Jan 19 2025 01:13:40
Module start 'content'
Timing: Jan 19 2025 01:13:41
Module end 'content'
Timing: Jan 19 2025 01:13:41
Script end

Main resources:

Total runtime0.7616 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 590.2891152.6250
Module start 'layout' 0.00590.0034 742.914139.4453
Module start 'content' 0.00930.7509 782.3594574.3359
Module end 'content' 0.76020.0014 1,356.695312.1641
Script end 0.7615  1,368.8594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4451160.0002
Check MTime0.00150.1912160.0001
Mysql Total
Database connection0.00080.108510.0008
Mysqli_queries0.713093.6252590.0121
Looping result0.00060.0759570.0000
Template Total0.734496.420.3672
Template load0.00200.256820.0010
Template processing0.732496.169220.3662
Template load and register function0.00020.022410.0002
states
state_id_array0.00070.092110.0007
state_identifier_array0.00060.079020.0003
Override
Cache load0.00160.2144200.0001
Sytem overhead
Fetch class attribute can translate value0.00060.079730.0002
Fetch class attribute name0.00100.129950.0002
XML
Image XML parsing0.00110.145230.0004
class_abstraction
Instantiating content class attribute0.00000.001350.0000
General
dbfile0.00090.1207220.0000
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs