1

I have the following xml which I'm accessing through simplexml:

<sequences>
    <sequence>
        <ImageUrl id="">
            http://www.image.com/image.jpg
        </ImageUrl>
        <photographer>name</photographer>
    </sequence>
    <sequence>
        <ImageUrl id="">
            http://www.image.com/image1.jpg
        </ImageUrl>
        <photographer>name 1</photographer>
    </sequence>
</sequences>

I need to pass this data to smarty and output in a template. I need to be able to output the first sequence image and photographer name and then the second. How can I do this? I can see that you can pass an array to smarty and then loop over it in the template but I essentially need to pass a multidimensional array, 1 array for each sequence node.

0

2 Answers 2

1

I ended up assigning the whole simplexml obj to a smarty and looped over it like to in the template:

{foreach from=$contents key=key item=item}
    {foreach from=$item key=k item=i}
        {if $k eq 'ImageUrl'}
            <img src="{$i}" />
        {/if}
        {if $k eq 'photographer'}
            <img src="{$i}" />
        {/if}
Sign up to request clarification or add additional context in comments.

Comments

0

Convert your XML to array then :

In php

<?php
$arr = array("first"=>1000, "second"=>1001, "third"=>1002);
$smarty->assign('myArray', $arr);
?>

In smarty template :

<ul>
{foreach from=$myArray item=myArray name=myArray}
    <li>{$myArray.first}</li>
    <li>{$myArray.second}</li>
    <li>{$myArray.third}</li>
{/foreach}
</ul>

3 Comments

no, I need to be able to output the first sequences image and name and then the second seperately
Then pass images in different variables instead of a single array, pass these variables to smarty, and echo it using {$var}
but there could be an arbitrary number of sequence items so that will never work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.