No it's not a bug, each item in ads is an SimpleXMLElement object (which
does contain the string) and to guarantee printing the correct value you
will need to cast it as a string.

foreach($adsFile->ad as $item) {
    $ads[] = array('title'    => (string)$item['title'],
                         'descr' => (string)$item['descr'],
                         'url'     => (string)$item['url']);
}

$template->set('ads' $ads);

OR try adding ''. to the beginning of each item...

<li tal:repeat="item ads"><a tal:attributes="href php:''.item['url']"
tal:content="php:''.item['title']"></a></li>

-Bobby

On Sat, Apr 4, 2009 at 11:42 PM, romtek <rom...@gmail.com> wrote:

> Hi,
>
> I have an XML file:
>
> <?xml version="1.0" encoding="utf-8"?>
> <ads>
> <ad title="test ad 1" descr="some short description 1" url="
> http://google.com";></ad>
>  <ad title="test ad 2" descr="some short description 2" url="
> http://yahoo.com";></ad>
>  <ad title="test ad 3" descr="some short description 3" url="
> http://msnbc.com";></ad>
> </ads>
>
> When I use in PHP like this, attributes are printed correctly:
>
> $adsFile = simplexml_load_file("ads.xml");
> foreach($adsFile->ad as $item)
> {
> echo $item['title'];
> }
>
> However, when I try to display the attribute "title" with a PHPTAL template
> like this:
>
> <li tal:repeat="item ads"><a tal:attributes="href php:item['url']"
> tal:content="php:item['title']"></a></li>
>
> I get the following as the content of the anchor element: title="test ad
> 1".
>
> Is this a bug?
>
> Thanks
>
> Roman
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>
>
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to