You are here: Re: [SMARTY] smarty + XML « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] smarty + XML

Posted by dc on 06/03/05 19:50

when is an array not an array? when its simpleXML
it seems simpleXML is hard to work with smarty.

this (smarty tpl) works:

<li>{$xml->example[0]->title}
<li>{$xml->example[1]->title}

gives me a nice list of titles.

a smarty section gives nothing (it doesnt loop)
{section name=id loop=$xml->example }

but a foreach *does* loop thru,
{foreach from=$xml->example item=ex }

but the item coming thru is the first leaf of the XML.

the only way seems to be to have two foreach loops. however, for each
cannot skip
(start=1) the first index (xml header stuff), so an if statement is needed.

-------
final kludge: (works)

{foreach from=$xml item=list name='outer' }
{if $smarty.foreach.outer.iteration>1}
{foreach from=$list item=ex name='loop' }


unfortunately this code is to be shown onscreen at a seminar, which is a
bit embarassing really.

/dc

On Sat, 04 Jun 2005 00:45:09 +0900, Monte Ohrt <monte@ohrt.com> wrote:

> If it is assigned as an object, then you must access in Smarty like such:
>
> {$ex->event}
>
> dc wrote:
>
>> thanks for the amazingly quick response...
>>
>>> If you're only getting the first letter, then your data structure may
>>> not be what you are expecting.
>>>
>>> What is the output of
>>>
>>> print_r($xml);
>>
>>
>>
>> SimpleXMLElement Object
>> (
>> [event] => Macromedia 集中ゼミ
>> [example] => Array
>> (
>> [0] => SimpleXMLElement Object
>> (
>> [title] => 四角+テキスト
>> [src] => demo01.php
>> [description] => 四角+テキスト。日本語対応
>> )
>>
>> [1] => SimpleXMLElement Object
>> (
>> [title] => 外部SWFファイル
>> [src] => demo02.php
>> [description] => SWF呼び出す
>> )
>>
>> )
>> )
>>
>>
>> do i have to convert the SimpleXMLElement Objects to simple arrays for
>> smarty?
>>
>> /dc
>>
>>
>> On Sat, 04 Jun 2005 00:33:51 +0900, Monte Ohrt <monte@ohrt.com> wrote:
>>
>>> If you're only getting the first letter, then your data structure may
>>> not be what you are expecting.
>>>
>>> What is the output of
>>>
>>> print_r($xml);
>>>
>>> ?
>>>
>>> dc wrote:
>>>
>>>> does smarty play nicely with objects created by PHP's simple xml?
>>>>
>>>> ---------------------- PHP
>>>> $xml = simplexml_load_file('assets/exList.xml');
>>>> $sm->assign("xml", $xml);
>>>>
>>>> ---------------------- XML
>>>> <exampleList>
>>>>
>>>> <event>集中ゼミ</event>
>>>>
>>>> <example>
>>>> <title>四角+テキスト</title>
>>>> <src>demo01.php</src>
>>>> <description>四角+テキスト。日本語対応</description>
>>>> </example>
>>>>
>>>> etc
>>>>
>>>> ---------------------- smarty template:
>>>> {foreach from=$xml item=ex }
>>>> {$ex.event}
>>>> {$ex.title}
>>>> {/foreach}
>>>>
>>>>
>>>> but this only gives me the first letter of the item...
>>>>
>>>> would the toplevel of the XML tree be passed into smarty?
>>>> eg exampleList/event
>>>>
>>>> exampleList/example [0]? first item?
>>>>
>>>>
>>>> thanks for any help. would have thot this would be on the smarty site
>>>> as XML display with smarty would seem to be a major use...
>>>>
>>>
>>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация