Re: [PHPTAL] Problem accessing attributes from a SimpleXML object in PHPTAL templates

2009-04-16 Thread Kornel LesiƄski

On 05.04.2009, at 07:42, romtek wrote:

tal:content="php:item['title']">


I get the following as the content of the anchor element:  
title="test ad 1".


Is this a bug?


Yes and no :)

It's unfortunate side-effect of support for printing SimpleXML  
objects. I've tweaked it in the latest PHPTAL version and attributes  
should now be printed as expected. Old weird behaviour will happen  
only when you add structure keyword.


Unfortunalely it can't be 100% fixed, because SimpleXML gives no  
sensible way of telling elements and attributes apart.


--
regards, Kornel




___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Problem accessing attributes from a SimpleXML object in PHPTAL templates

2009-04-05 Thread Bobby
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...



-Bobby

On Sat, Apr 4, 2009 at 11:42 PM, romtek  wrote:

> Hi,
>
> I have an XML file:
>
> 
> 
> http://google.com";>
>  http://yahoo.com";>
>  http://msnbc.com";>
> 
>
> 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:
>
>  tal:content="php:item['title']">
>
> 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


[PHPTAL] Problem accessing attributes from a SimpleXML object in PHPTAL templates

2009-04-04 Thread romtek
Hi,

I have an XML file:



http://google.com";>
http://yahoo.com
">
http://msnbc.com
">


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:



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