Re: [Phplib-users] url() in templates
Brought to you by:
nhruby,
richardarcher
From: Richard A. <rh...@ju...> - 2001-08-14 10:09:03
|
At 11:38 AM +0200 14/8/01, Guenther Theilen wrote: >I'm working with templates and session. Now I want to replace the >regular links (e.g. <a href="test.php">foo</a>) in my >index.tpl.html-teplate file by something like this: ><a href=" $sess->url('test.php') ">foo</a> >But I'm not able to figure out how to get php to parse the php-part in >the file. Renaming the index.tpl.html to index.tpl.php had no effect. >Anybody any hints? Hi Guenther, You don't want to be executing your templates!! There are two choices here. The way I'd normally do it is to set up my template like: <a href="test.php{sess_url_suffix}">foo</a> Then generate a sess_url, grab the bit from the '?' to the end into $sess_url_suffix and do: set_var("sess_url_suffix", $sess_url_suffix) Obviously a pretty nasty hack to work around a missing template.inc feature. The nicer way was posted by Lukasz Kowalczyk to the old phplib mailing list back in May 2000 and involves a patch to template.inc so that it knows about session URLs. Note that I've never tried this patch, and it should be implemented by subclassing Template and overriding the existing finish function. A snippet of the patch is below. Please excuse the long lines. ...Richard. * str: string to finish. */ function finish($str) { global $sess; /* First substitute all URLs which contain question marks (in this case session id * is appended after an ampersand (&). With the next pass substitute URLs not containing * question marks - this time use `?' as a separator. */ if (isset($sess) && $sess->mode == "get") { $str = preg_replace('/<[aA]([^>]+)[hH][rR][eE][fF]="(([^"?]+)\?([^"?]*))"/', '<a\1href="\2&'.$sess->cookiename.'='.$sess->id.'"', $str); $str = preg_replace('/<[aA]([^>]+)[hH][rR][eE][fF]="([^"?]+)"/', '<a\1href="\2?'.$sess->cookiename.'='.$sess->id.'"', $str); $str = preg_replace('/(<[fF][oO][rR][mM][^>]*>)/', '\1<input type="hidden" name="'.$sess->cookiename.'" value="'.$sess->id.'">', $str); } switch ($this->unknowns) { case "keep": break; |