By: TBS Newbie
Date: 2014-03-30
Time: 12:53
|
PHP array to Template file
Hello Everyone,
I been trying to solve this for days, but to no avail. I have merged arrays as a result of parsing an xml file. The print_r output is shown below.
Array (
[0] => Array (
[0] => Array (
[link] => About Us
[url] => index=about_us
)
[1] => Array (
[link] => Contact
[url] => title=testing_again
)
[copyright] => YourSite.Com 2014
[title] => Welcom to our site
[author] => MySite.com
[content] => This is our site
)
My php codes looks like this
$TBS->MergeBlock('content',$array);
Can somebody please tell me how I can write the codes for the template file?
|
By: Skrol29
Date: 2014-03-30
Time: 22:44
|
Re: PHP array to Template file
Hi Newbie,
I have a problem with you data structure: why the list of url/link are in the same level as whom information such as Copyright, Title, .... ?
Bluit this way, it is not possible to separate the url/link items from the whom informations.
|
By: TBS Newbie
Date: 2014-03-31
Time: 01:45
|
Re: PHP array to Template file
Hi Skrol29,
Thank you for responding to my question I really appreciate it. Below is an output from a revised PHP which not using
$TBS->MergeBlock('data', $array);
The print_r of the array returns
Array ( [0] => Array (
[0] => Array (
[link] => About Us
[url] => title=about_us
)
[1] => Array (
[link] => Testing Again
[url] => title=testing_again
)
[2] => Array (
[link] => This Is A Sample Article
[url] => title=this_is_a_sample_article
)
[3] => Array (
[link] => This Is A Second Sample Article
[url] => title=this_is_a_second_sample_article
)
)
)
The problem that I currently having is that I cannot pass the array to the template. I am not really sure I how to do this on TBS. What I have on my template file was like this
[data.link;block=li]
[data.link]
Once again, thanks a lot..
|
By: Skrol29
Date: 2014-03-31
Time: 02:16
|
Re: PHP array to Template file
And can you give an example of result you want to have (corresponding to the given data) ?
|
By: TBS Newbie
Date: 2014-03-31
Time: 02:49
|
Re: PHP array to Template file
Hi,
Thanks again. my apology for not including it on my first post. The output I am trying to achieved are links. Something like this
<a href="read/[data.url]"> [data.link]</a>
I have a router that will redirect to the specific page based on the data.url..
Thanks
|
By: TBS Newbie
Date: 2014-03-31
Time: 06:26
|
Re: PHP array to Template file
Additional information. If I do this in PHP
foreach($data as $item){
echo '<a href="'.$item['url'].'">'.$item['link'].'</a><br/>';
}
it works perfectly, but I cannot do it in the template file.
|
By: Skrol29
Date: 2014-03-31
Time: 23:15
|
Re: PHP array to Template file
PHP side :
$TBS->MergeBlock('data',$data);
|
HTML side :
<div><a href="[data.url;block=div]"> [data.link]</a></div> |
or
<span><a href="[data.url;block=span]"> [data.link]</a></br></span> |
or
<a href="[data.url;block=_]"> [data.link]</a></br> |
"block=_" means the block is defined on the text line.
|
By: TBS Newbie
Date: 2014-04-02
Time: 05:28
|
Re: PHP array to Template file
Skrol29,
Thanks for your reply, It works.. thank you, thank you for your help..
|
|
Posting in progress.
Please wait...
|