Test an url before display them

Author Message

Sébastien Antoniotti

Friday 01 December 2006 6:45:37 am

Hi,

In a template I build on the fly links for htm pages like this :

{def $url_archive=concat("http://www.site.com/infos/", $temp_year,"/",$moisarchive,"_", $temp_year, "/",$view_parameters.day, "_",$moisarchive,".htm"))}
	
	<a href="{$url_archive}" target="_blank">{$url_archive}</a>

and I have this output : http://www.site.com/infos/2006/novembre_2006/12_novembre.htm

But I want to test if this url is correct, before display it, because it's possible that the .htm document doesn't exist, so I must test it like than a test with the "file_exist" fonction of php... but I haven't found the good template operator =(

eZ Publish Freelance
web : http://www.webaxis.fr

Nabil Alimi

Tuesday 05 December 2006 2:21:19 pm

Hi Sébastien,

Whenever you need a php method, you may add it to the template.ini file :

[PHP]
# A list with php functions and their equivelant template operator names
# Giving the operators a different name from the PHP functions
# are recommended, that way you ensure that all operators follow
# the same naming guidelines. It also means that you can change the
# php function later on without doing template changes.
PHPOperatorList[]
PHPOperatorList[urlencode]=urlencode

However this only works with operators that handles one parameter max.

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Sébastien Antoniotti

Tuesday 05 December 2006 10:06:36 pm

Hi Nabil,

Thanks a lot for this feature !!!

I think that I can resolve my problem with it,

Thanks again,
Seb.

eZ Publish Freelance
web : http://www.webaxis.fr

kracker (the)

Wednesday 06 December 2006 12:08:05 am

While Nabil is correct about the use of eZ publish's built in PHPOperatorList feature.
<i>http://ez.no/ezpublish/documentation/development/kernel/custom_template_operators
http://ez.no/ezpublish/documentation/development/extensions/template_operator
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators</i>

I find that feature horribly limited as it <i>only</i> works with PHP functions which accept <b>only one argument</b>, this greatly limits the PHP functions you can use.

I encourage you to use the wrapper operator contribution instead!
<i>http://ez.no/community/contribs/template_plugins/wrapper_operator</i>

The wrapper operator allows for use of any PHP function regardless of number of arguments or parameters.

Cheers,
<i>//kracker</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Sébastien Antoniotti

Wednesday 06 December 2006 6:59:03 am

You are right, this solution is better an more usefull !!

Thanks a lot ;)

eZ Publish Freelance
web : http://www.webaxis.fr

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 18 2025 16:05:32
Script start
Timing: Jan 18 2025 16:05:32
Module start 'layout'
Timing: Jan 18 2025 16:05:32
Module start 'content'
Timing: Jan 18 2025 16:05:33
Module end 'content'
Timing: Jan 18 2025 16:05:33
Script end

Main resources:

Total runtime0.8114 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 591.6328152.6250
Module start 'layout' 0.00640.0024 744.257839.4453
Module start 'content' 0.00880.8009 783.7031621.1250
Module end 'content' 0.80970.0016 1,404.828116.1641
Script end 0.8113  1,420.9922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3827160.0002
Check MTime0.00130.1563160.0001
Mysql Total
Database connection0.00110.130110.0011
Mysqli_queries0.745391.8609650.0115
Looping result0.00060.0708630.0000
Template Total0.783096.520.3915
Template load0.00200.241920.0010
Template processing0.781096.263920.3905
Template load and register function0.00010.012910.0001
states
state_id_array0.00070.085210.0007
state_identifier_array0.00110.133520.0005
Override
Cache load0.00170.2041380.0000
Sytem overhead
Fetch class attribute can translate value0.00070.092230.0002
Fetch class attribute name0.00100.118380.0001
XML
Image XML parsing0.00170.213630.0006
class_abstraction
Instantiating content class attribute0.00000.0025100.0000
General
dbfile0.00160.2017300.0001
String conversion0.00000.001040.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
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs