romtek | 2 May 2011 19:33
Picon

Re: Want an alias for tal:attributes

Is it possible to implement?

On Wed, Apr 13, 2011 at 7:21 PM, romtek <romtek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
When there's a lot of code on a page, being able to use as little text as possible is very desirable. I'd like to be able to use a short alias for tal:attributes. E.g. tal:attr. It's intuitive and familiar to people from other libraries.

_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Fernando Martins | 7 May 2011 15:19
Picon

issue with variable defined in a full page macro

Hi,

I use ZPT with zope and I was checking out PHPTAL. One fundamental issue 
I found is that a variable defined in a macro is not made available to 
the elements of the calling zpt. That is, given this macro, peopleMain.zpt

<html   metal:define-macro="main"  tal:define="people php:peopleGet()">
<head>
</head>
<body>

<div metal:define-slot="content_main">
</div>

</body>
</html>

which is being used as [Browser] -> people.php -> people.zpt -> 
peopleMain.zpt

where peopleGet is a function in people.php which processes the template 
people.zpt which is:

<html metal:use-macro="person.zpt/main"><head>
</head>
<body>
<div metal:fill-slot="content_main">
<ul>
<li tal:repeat="user people" tal:content="user/name"></li>
</ul>
</div>
</body>
</html>

I get the error:

exception 'PHPTAL_VariableNotFoundException' with message 'Unable to 
find variable 'people' in current scope' in /var/www/PHP/people.zpt

This is a real pity, because in the same way that people.zpt defines the 
common elements of a web site, so would do the global variable people, 
ie, keeping all the common data for all the pages. This limitation 
(bug?) forces to include a call to peopleGet in all php/zpt pages.

Regards,
Fernando
Kornel Lesiński | 8 May 2011 01:17
Gravatar

Re: issue with variable defined in a full page macro

On Sat, 07 May 2011 14:19:26 +0100, Fernando Martins  
<fernando@...> wrote:

> This is a real pity, because in the same way that people.zpt defines the  
> common elements of a web site, so would do the global variable people,  
> ie, keeping all the common data for all the pages. This limitation  
> (bug?) forces to include a call to peopleGet in all php/zpt pages.

Slots "see" variables from context (file) they are run in, not from  
context where the macro is defined.

Instead of:

<div metal:define-slot="content_main"/>

you could use:

<div metal:use-macro="${callback}" />

and

--

-- 
regards, Kornel Lesiński
Kornel Lesiński | 8 May 2011 01:20
Gravatar

Re: issue with variable defined in a full page macro


(oops, I've pressed send accidentally :)

Sooo, replace these:

<html metal:use-macro="person.zpt/main">
+
<div metal:fill-slot="content_main">

with:

<html metal:use-macro="person.zpt/main" tal:define="callback  
'display-list'>
+
<div metal:define-macro="display-list">

Basically use another macro instead of a slot.

--

-- 
regards, Kornel Lesiński
Levi Stanley | 8 May 2011 04:11

Re: issue with variable defined in a full page macro

I think Fernando was trying to instead of defining people everytime, he wanted to define it in the macro he was using everywhere so he wouldn't have to define in every presentation view.  He says he is able to do it in ZPT.  However, I have never used ZPT, but thought it was a interesting way to make sure your macro makes the call instead of always remembering to include it in your use-macro or slot, or in your controller.

If ZPT does implement this, all we need to do is change the statement on the front of the site to:

PHPTAL is a templating engine for PHP5 that partially implements brilliant Zope Page Templates syntax:


jk'ing.


On 05/07/11 19:20, Kornel Lesiński wrote:

(oops, I've pressed send accidentally :)

Sooo, replace these:

<html metal:use-macro="person.zpt/main">
+
<div metal:fill-slot="content_main">

with:

<html metal:use-macro="person.zpt/main" tal:define="callback 'display-list'>
+
<div metal:define-macro="display-list">


Basically use another macro instead of a slot.



_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Fernando Martins | 8 May 2011 17:14
Picon

Re: issue with variable defined in a full page macro

I'm afraid I can't understand what you are trying to achieve there. What 
is the effect of the tal:define="callback 'display-list'" ?? what do the 
quotes do to display-list? and how would I use the callback? Sorry, very 
confused...

I have a main page template person.zpt which defines the layout for all 
the pages of the web site. Every other page, say people.zpt, 
meeting.zpt, team.zpt merely fills in the slots. All I wanted was to 
avoid redefining common variables in all pages. Just factoring out the 
common data into the common template.

Fernando

Kornel Lesiński wrote:
>
> (oops, I've pressed send accidentally :)
>
> Sooo, replace these:
>
> <html metal:use-macro="person.zpt/main">
> +
> <div metal:fill-slot="content_main">
>
> with:
>
> <html metal:use-macro="person.zpt/main" tal:define="callback 
> 'display-list'>
> +
> <div metal:define-macro="display-list">
>
>
> Basically use another macro instead of a slot.
>
>
Fernando Martins | 8 May 2011 17:16
Picon

Re: issue with variable defined in a full page macro

yep, that's it :)

Levi Stanley wrote:
> I think Fernando was trying to instead of defining people everytime, 
> he wanted to define it in the macro he was using everywhere so he 
> wouldn't have to define in every presentation view.  He says he is 
> able to do it in ZPT.  However, I have never used ZPT, but thought it 
> was a interesting way to make sure your macro makes the call instead 
> of always remembering to include it in your use-macro or slot, or in 
> your controller.
>
> If ZPT does implement this, all we need to do is change the statement 
> on the front of the site to:
>
> PHPTAL is a templating engine for PHP5 that *partially* implements 
> brilliant Zope Page Templates syntax:
>
>
> jk'ing.
>
Darrell Noice | 11 May 2011 08:42
Favicon

Evaluating tal:attributes Generated By PreFilters

Premise:

I am writing a Pre Filter, using filterDOM, to locate all elements
that contain an i18n:translate attribute.  These elements extracted
from the DOM, wrapped in an element that contains information about
the translation, eg the token used to look up the translation and any
i18n:name attributes that may exist, and then the wrapper is inserted
in its place.

Goal (in case this sounds crazy to you):

Working on a "point and click" translation editor, allowing users to
simply click on the appropriate UI element to activate a WYSIWYG for
that particular translated item.

Problem:

I'm so far unable to find documentation on or figure out how to get
standard PHPTAL attributes, eg "tal:attributes" to evaluate after
they've been inserted by the Pre Filter.  I've got pretty much
everything working, but this is was I'm currently ending up with:

<translation variables="" tal:attributes="token string:account" language="en">

where as I want it to look like:

<translation variables="" token="account" language="en">

Relevant Code:

foreach(...) {
...
$new_attrs = array();
$new_attrs[] = new PHPTAL_Dom_Attr("variables","",implode(",",$vars),"UTF-8");
$new_attrs[] = new PHPTAL_Dom_Attr("tal:attributes","","token
{$token}","UTF-8");
$new_attrs[] = new PHPTAL_Dom_Attr("language","","en","UTF-8");

$wrapper = new PHPTAL_Dom_Element("translation","",$new_attrs,$child->getXmlnsState());
$node->replaceChild($wrapper,$child);
$wrapper->appendChild($child);
...
}

Thank you in advance for any input.

Darrell Hamilton,
Software Developer,
4over, Inc
darrelln@...
Kornel Lesiński | 11 May 2011 23:05
Gravatar

Re: issue with variable defined in a full page macro

On Sun, 08 May 2011 16:14:46 +0100, Fernando Martins  
<fernando@...> wrote:

> I'm afraid I can't understand what you are trying to achieve there. What  
> is the effect of the tal:define="callback 'display-list'" ?? what do the  
> quotes do to display-list? and how would I use the callback? Sorry, very  
> confused...

I've meant using callback (macro called from macro) instead of slots.

e.g. your code modified to use callbacks:

<html   metal:define-macro="main"  tal:define="people php:peopleGet()">
<head>
</head>
<body>

<div metal:use-macro="${callback}" tal:comment="will call any macro named  
in callback variable">
</div>

</body>
</html>

<html metal:use-macro="person.zpt/main" tal:define="callback  
string:myfile.zpt/content_main" tal:comment="variable tells main macro to  
call content_main below"><head>
</head>
<body>
<div metal:define-macro="content_main">
<ul>
<li tal:repeat="user people" tal:content="user/name"></li>
</ul>
</div>
</body>
</html>

> I have a main page template person.zpt which defines the layout for all  
> the pages of the web site. Every other page, say people.zpt,  
> meeting.zpt, team.zpt merely fills in the slots. All I wanted was to  
> avoid redefining common variables in all pages. Just factoring out the  
> common data into the common template.

If you have certain variables on all pages, why not simply set them from  
PHP?

In PHPTAL slots are executed in context where fill-slot is used, not in  
context where define-slot is, so what you're trying to achieve is not  
possible with slots.

I wasn't aware that in Zope context is different. Can Zope's fill-slot use  
variables from both its context and the macro? If both macro and context  
of fill-slot have variable with same name, which one "wins"?

--

-- 
regards, Kornel Lesiński
Kornel Lesiński | 11 May 2011 23:25
Gravatar

Re: Evaluating tal:attributes Generated By PreFilters

On Wed, 11 May 2011 07:42:50 +0100, Darrell Noice
<darrelln@...>  
wrote:

> foreach(...) {
> ...
> $new_attrs = array();
> $new_attrs[] = new  
> PHPTAL_Dom_Attr("variables","",implode(",",$vars),"UTF-8");
> $new_attrs[] = new PHPTAL_Dom_Attr("tal:attributes","","token
> {$token}","UTF-8");

PHPTAL's DOM uses XML namespaces. In this case you're creating attribute  
named "tal:attributes" in default namespace, but you need attribute named  
"attributes" in "http://xml.zope.org/namespaces/tal" namespace.

That should work and setAttributeNS will be a little prettier than new  
DOM_Attr:

$wrapper = new PHPTAL_Dom_Element("translation","",array(),  
$child->getXmlnsState());
$wrapper->setAttributeNS('http://xml.zope.org/namespaces/tal',  
'attributes', "token $token");

--

-- 
regards, Kornel Lesiński

Gmane