Forums / General / Test an url before display them

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