a b | 2 Oct 2008 20:15
Picon
Gravatar

multiple pre/post filters

Hi,

How to add two or more post/pre filters to the template?
_prefilter is not an array, so just last filter is executed.

--
takeshin
_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Kornel Lesiński | 3 Oct 2008 11:54
Picon
Favicon
Gravatar

Re: multiple pre/post filters

On 02-10-2008 at 19:15:47 a b <admirau@...> wrote:

> How to add two or more post/pre filters to the template?
> _prefilter is not an array, so just last filter is executed.

class MyBunchOfFilters implements PHPTAL_Filter
{
	function filter($code)
	{
		foreach($this->myfilters as $f) $code = $f->filter($code);
		return $code;
	}
}

--

-- 
regards, Kornel
a b | 3 Oct 2008 22:56
Picon
Gravatar

Namespace with shorter notatnion

Hi,

How to modify default namespace
to have shorter notatnion of:
<tal:block i18n:translate="">my string</tal:block>
(assuming I do not use i18n:translate="var")

for example as:
<tal:lang>my string</tal:lang>

--
reagards,
takeshin
_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Kornel Lesiński | 6 Oct 2008 13:32
Picon
Favicon
Gravatar

Re: Namespace with shorter notatnion

On 03-10-2008 at 21:56:04 a b <admirau@...> wrote:

> How to modify default namespace
> to have shorter notatnion of:
> <tal:block i18n:translate="">my string</tal:block>
> (assuming I do not use i18n:translate="var")
>
> for example as:
> <tal:lang>my string</tal:lang>

There's nothing within TAL syntax that can do it. You could extend PHPTAL  
to create <tal:lang> tag, but the easiest solution might be to write a  
prefilter:

class EzI18n extends PHPTAL_Filter
{
   function filter($src)
   {
     return preg_replace('!<my:lang>(.*?)</my:lang>!s','<tal:block  
i18n:translate="">\1</tal:block>',$src);
   }
}

$phptal->setPreFilter(new EzI18n());

(regular expressions used for XML aren't very elegant - you could use  
DOM+XSLT instead)

--

-- 
regards, Kornel
admi | 8 Oct 2008 16:57
Picon
Favicon

assigned fields

Hello!

This is example code:

$t = new Tal();
$t->title = "TitleTest";
$t->content = "ContentText";
$t->setTemplate("content.html");
$t->execute(); //here $t->content should be unset

$t->setTemplate("title.html");
$t->execute(); //I'd like to have only $t->title

I'd like to delete/unset fields that have been used in current template
(content.html) while calling execute().

Does anyone know where I can do this?
Kornel Lesiński | 8 Oct 2008 18:12
Picon
Favicon
Gravatar

Re: assigned fields

On 08-10-2008 at 15:57:51 admi <adm113@...> wrote:

> This is example code:
>
> $t = new Tal();
> $t->title = "TitleTest";
> $t->content = "ContentText";
> $t->setTemplate("content.html");
> $t->execute(); //here $t->content should be unset
>
> $t->setTemplate("title.html");
> $t->execute(); //I'd like to have only $t->title
>
> I'd like to delete/unset fields that have been used in current template
> (content.html) while calling execute().
>
> Does anyone know where I can do this?

I'm not sure what you're trying to achieve.

If you just want to unset some variables, then $t->content = NULL; should  
be good enough.

You don't need to worry about local variables in templates - they're not  
preserved (i.e. tal:define="title 'blah'" won't affect $t->title).

If you set global variables in templates, then you could create a "backup"  
copy of PHPTAL object like this (I haven't tested this one):

$tal = new PHPTAL();
$tal->title = "TitleTest";

$freshtalcopy = clone $tal; // create copy of PHPTAL with all variables

$tal->content = "ContentText";
$tal->setTemplate("content.html");
$tal->execute();

$tal = $freshtalcopy;

$tal->setTemplate("title.html");
$tal->execute();

--

-- 
regards, Kornel
Axel Zöllich | 9 Oct 2008 00:57
Picon

php array -> TAL path:

Bonsoir,

this php

abc.php:
$ergebnis = $mysqli->query("SELECT * FROM farbe");
while ($zeile = $ergebnis->fetch_object()) {
  $typen[farben][][kuerzel] = $zeile->kuerzel;
  $typen[farben][][bez] = $zeile->bez;
}

and html

abc.html:
<fieldset>
 <legend>Farben</legend>
 <span tal:repeat="farbe typen/farben">
 <input type="checkbox" tal:attributes="name farbe/kuerzel; id 
farbe/kuerzel" />
 <label tal:content="farbe/bez" tal:attributes="for 
farbe/kuerzel">Weiß!</label>
 </span>
</fieldset>

throws 

exception 'PHPTAL_Exception' with message 'Unable to find array key "bez" in 
path "bez"' 
exception 'PHPTAL_Exception' with message 'Unable to find array key "kuerzel" 
in path "kuerzel"'

What's going wrong here?
TALs "path:" generally accesses php arrays without any problem. I'm somehow 
blind at the moment. 

Thanks for enlightenment.

xel

--

-- 
Wir verwenden ausschließlich blaue Elektronen aus biologischem Anbau.
Kornel Lesiński | 9 Oct 2008 11:22
Picon
Favicon
Gravatar

Re: php array -> TAL path:

On 08-10-2008 at 23:57:05 Axel Zöllich <faxel@...> wrote:

> abc.php:
> $ergebnis = $mysqli->query("SELECT * FROM farbe");
> while ($zeile = $ergebnis->fetch_object()) {
>   $typen[farben][][kuerzel] = $zeile->kuerzel;
>   $typen[farben][][bez] = $zeile->bez;
> }

On each loop iteration you're creating two array elements in  
$typen[farben], one with *only* "kuerzel" key, and another one with *only*  
"bez" key.

Your PHPTAL template seems to expect that every array element has both  
keys. If you wanted both keys in one element, then use something like this:

$typen['farben'][] = array(
	'kuerzel'=>$zeile->kuerzel,
	'bez'=>$zeile->bez,
);

and if you really want array with keys interlaced, then add  
tal:condition="exists:farbe/bez" and tal:condition="exists:farbe/kuerzel"  
on elements which use these expressions.

--

-- 
regards, Kornel
Axel Zöllich | 9 Oct 2008 13:05
Picon

Re: php array -> TAL path:

> On each loop iteration you're creating two array elements in
> $typen[farben], one with *only* "kuerzel" key, and another one with *only*
> "bez" key.

Thank you very much.
I've been really blind ...

xel

--

-- 
Wir verwenden ausschließlich blaue Elektronen aus biologischem Anbau.
admi | 9 Oct 2008 21:11
Picon
Favicon

Re: assigned fields


> I'm not sure what you're trying to achieve.
> 
> If you just want to unset some variables, then $t->content = NULL; should  
> be good enough.
> 

Thanks for the answer!

I can set it to null if I know it was used in content.html. What if I don't know
wchich variables have been used ?

content.html uses $t->content, but I'd like to unset $t->content after executing
and not knowing that content.html used only $t->content (it could use $t->title).

Gmane