Miko Väli | 1 Mar 2009 10:58
Picon

Re: Repeat scope issue

Wow, this is really cool. Thanks alot!
I had the thought to write about it to the mailing list too, but I 
thought that it should be that way because it is in PHP.

No more tal:repeat="r_user users"!

Kornel Lesiński wrote:
> On 28.02.2009, at 00:41, Richard Cernava wrote:
>
>> I've noticed that PHPTal places the repeat value variable in the ctx
>> object, which happens to be the same scope as all others
>> assigned to view.
> [...]
>> I'm not sure if this is a bug or not considering standard php practice
>> is to make these variables non local scope. I do feel in PHPTal that a
>> repeat should have it's own local scope, at least for it's variable.
>>
>> What is the opinion on this?
>
> It's a bug. Each element should have its own scope, and assignment 
> inside tal:repeat shouldn't leak outside the loop.
>
> This is fixed in SVN.
>
Moritz Baumann | 1 Mar 2009 23:41
Picon

Re: Process dynamically inserted content (feature request?)

Levi Stanley <levi <at> ...> writes:

> Sounds like what you are describing is a Site / Page Controller?

I tried to explain the script a bit further to make clear how the skeleton
template is being used. It just defines the general Layout of the page. I wanted
to insert the actual content by making the skeleton template call macros whose
names are stored in an array which is passed to the template (one per content
area which the skeleton provides).

This works fine as long as the inserted content is e.g. a tag cloud of a blog. I
can just call the macro blog.html/tag_cloud. But if it is text stored inside a
database which I want to be treated as a part of the template (it might be a
text page that links to a blog entry whose URI could change, therefore I want
the link to be generated automatically), it won't.

The solution Kornel proposed would perfectly work as long as only the »main
content« of the requested page (which would then be the template I instruct
PHPTAL to parse and which would call the skeleton template as a macro) can be
such text. But that'd still be a serious restriction.

Moritz
Levi Stanley | 2 Mar 2009 05:59

Re: Re: Process dynamically inserted content (feature request?)

Hmm, still seems to me your solution can be solved in the controller, instead of bogging the template layer with something it shouldn't really concern itself with.  The controller decides on the layout, and the view, and depending on that information it request a different view that works with that item.  If something does or doesn't exists you should have set up the presentation logic to handle all these cases.

Bet regards,
Levi





Moritz Baumann wrote:
Levi Stanley <levi <at> ...> writes:
Sounds like what you are describing is a Site / Page Controller?
I tried to explain the script a bit further to make clear how the skeleton template is being used. It just defines the general Layout of the page. I wanted to insert the actual content by making the skeleton template call macros whose names are stored in an array which is passed to the template (one per content area which the skeleton provides). This works fine as long as the inserted content is e.g. a tag cloud of a blog. I can just call the macro blog.html/tag_cloud. But if it is text stored inside a database which I want to be treated as a part of the template (it might be a text page that links to a blog entry whose URI could change, therefore I want the link to be generated automatically), it won't. The solution Kornel proposed would perfectly work as long as only the »main content« of the requested page (which would then be the template I instruct PHPTAL to parse and which would call the skeleton template as a macro) can be such text. But that'd still be a serious restriction. Moritz _______________________________________________ PHPTAL mailing list PHPTAL-CzyLcWPZiU5MT9OEwdum/5owlv4uC7bZ@public.gmane.org http://lists.motion-twin.com/mailman/listinfo/phptal

_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Kornel Lesiński | 2 Mar 2009 11:05
Picon
Favicon
Gravatar

Re: Re: Process dynamically inserted content (feature request?)

On 01-03-2009 at 22:41:35 Moritz Baumann <flamingmo@...> wrote:

>> Sounds like what you are describing is a Site / Page Controller?
>
> I tried to explain the script a bit further to make clear how the  
> skeleton template is being used. It just defines the general Layout of the page.  
> I wanted to insert the actual content by making the skeleton template call macros  
> whose names are stored in an array which is passed to the template (one per  
> content area which the skeleton provides).

Do you need to store PHPTAL code in the database, or is static XHTML enough?

In the latter case you could use structure keyword:

<tal:block tal:repeat="block blocks">
	<tal:block tal:condition="block/isMacro" metal:use-macro="${block/macroName}"/>
	<tal:block tal:condition="block/isStatic" tal:content="structure block/staticXHTML"/>
</tal:block>

If you insist on calling macros from non-disk templates, then there is such possibility actually.

Add this function to PHPTAL class (I'm not sure why it's not there already :)

function addResolver(PHPTAL_SourceResolver $r)
{
	$this->_resolvers[] = $r;
}

and implement your PHPTAL_SourceResolver class that will return PHPTAL_Source object. This allows you
to fake a filesystem :)

--

-- 
regards, Kornel
Alister Cameron | 3 Mar 2009 01:34
Gravatar

Disabling PHP?

Folks,


Need your wisdom.

Because I'm using PHPTAL in a WordPress theme, I want to disable PHP except for some very basic logic operations.

Has anyone done this, and if so, how?

Is there some elegant and simple way to control which PHP functions can be called, etc??

Any advice much appreciated.

Cheers,

-Alister

---
Alister Cameron // Blogologist

Mob. 04 0404 5555
Fax 03 8610 0050

Click here to find me online:
_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Kornel Lesiński | 3 Mar 2009 11:05
Picon
Favicon
Gravatar

Re: Disabling PHP?

On 03-03-2009 at 00:34:53 Alister Cameron
<alister.cameron@...> wrote:

> Because I'm using PHPTAL in a WordPress theme, I want to disable PHP  
> except for some very basic logic operations.
>
> Has anyone done this, and if so, how?
>
> Is there some elegant and simple way to control which PHP functions can  
> be called, etc??
>
> Any advice much appreciated.

There is no such option.

You could make insertion of PHP difficult by removing php prefix from TalesInternal.php and
"self::ST_PREPROC" case from XmlParser.php, but since PHPTAL wasn't designed to stop anybody from
using PHP, I can't guarantee that this will be secure.

--

-- 
regards, Kornel
Szymek Przybył | 3 Mar 2009 13:58
Picon
Gravatar

Multilevel list menu - must done in recursion, can be done in phptal?

Hi!

I have on page multilevel list menu. To done this menu, I make 
multilevel array. For max two level menu in phptal, this works:
    <ul>
        <li tal:repeat="menuItem menuItems">
            <a tal:attributes="href 
php:isset(menuItem['url'])?menuItem['url']:'#'" 
tal:content="menuItem/name"/>
            <ul tal:condition="php:menuItem['type']=='menu'">
                <li tal:repeat="menuItem_2 menuItem/children">
                    <a tal:attributes="href 
php:isset(menuItem_2['url'])?menuItem_2['url']:'#'" 
tal:content="menuItem_2/name"/>
                </li>
            </ul>
        </li>
    </ul>

If element is url - I give this url to href, if this is menu - after <a> 
element i add <ul> list with children of this menu. But what, if I want 
to do such as menu without any limits of levels? One way to do it is to 
prepare string in php with this menu, by recursion function, and then 
put it in phptal with structure expression.
But is there some way to do it in phptal?

cheers!
szymek
Kornel Lesiński | 3 Mar 2009 14:08
Picon
Favicon
Gravatar

Re: Multilevel list menu - must done in recursion, can be done in phptal?

On 03-03-2009 at 12:58:02 Szymek Przybył <apocalyptiq@...> wrote:

> I have on page multilevel list menu. 

Please read FAQ entry titled "Output trees recursively (e.g. nested multi-level menus)"
http://phptal.motion-twin.com/faq.html#q-trees

--

-- 
regards, Kornel
Szymek Przybył | 3 Mar 2009 14:21
Picon
Gravatar

Re: Multilevel list menu - must done in recursion, can be done in phptal?

Something like this:

    <ul metal:define-macro="menu" tal:condition="menuItems">
        <li tal:repeat="menuItem menuItems">
            <a tal:attributes="href 
php:isset(menuItem['url'])?menuItem['url']:'#'" 
tal:content="menuItem/name"/>
            <tal:block tal:define="menuItems menuItem/children" 
metal:use-macro="menu"/>
        </li>
    </ul>

Doesn't works, what I do wrongly?

cheers!
szymek
Szymek Przybył | 3 Mar 2009 14:31
Picon
Gravatar

Re: Multilevel list menu - must done in recursion, can be done in, phptal?

I forget to add <tal:block metal:use-macro="menu"/> after this menu 
definition, now:

<ul metal:define-macro="menu" tal:condition="exists:menuItems">
    <li tal:repeat="menuItem menuItems">
        <a tal:attributes="href 
php:isset(menuItem['url'])?menuItem['url']:'#'" 
tal:content="menuItem/name"/>
        <tal:block tal:condition="exists:menuItem/children">
            <metal:block tal:define="menuItems menuItem/children" 
metal:use-macro="menu"/>
        </tal:block>
    </li>
</ul>

<tal:block metal:use-macro="menu"/>

 it works, thanks kornel! :D

cheers!
szymek

Gmane