Categories > TinyButStrong general >

trouble with nested arrays

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Werner
Date: 2004-08-25
Time: 22:07

trouble with nested arrays

I try to Output a Newsfeed with tbs. I have looked at the Manual but still no idea.
The Array has the following structure:

array(7) {
  ["encoding"]=>
  string(0) ""
  ["title"]=>
  string(15) "Mozilla Dot Org"
  ["link"]=>
  string(22) "http://www.mozilla.org"
  ["description"]=>
  string(23) "the mozilla.org website"
  ["items_count"]=>
  int(15)
  ["items"]=>
  array(15) {
    [0]=>
    array(2) {
      ["title"]=>
      string(21) "Mozilla Japan Created"
      ["link"]=>
      string(52) "http://www.mozilla.org/press/mozilla-2004-08-18.html"
    }
    [1]=>
    array(2) {
      ["title"]=>
      string(19) "Mozilla 1.8 Alpha 3"
      ["link"]=>
      string(38) "http://www.mozilla.org/releases/#1.8a3"
    }
  }
}

Any suggestions are welcome.
Thanks
By: Skrol29
Date: 2004-08-26
Time: 02:59

Re: trouble with nested arrays

Hi Werner,

I don't think you can do it in one MergeBlock() call.
I suggest that you use sub-blocks for the second level of array (items). But you will need to use a custom function (easy to code) to merge sub-blocks for items because second level of array is not supported in native.
By: Werner
Date: 2004-08-26
Time: 15:34

Re: trouble with nested arrays

Thanks for your Answer.

What you mean is adding a data source and rearrange the Array?
Is there a example which is close to what i try to do?
Its so easy to do it with nested foreach loops in Smarty :/
Please tell me more about the custom function and what it should do exactly.
Btw, the Array is generated with lastRSS

Regards,
Werner
By: Skrol29
Date: 2004-08-26
Time: 17:59

Re: trouble with nested arrays

I just mean to add a TBS custom data source type for reading nested arrays. No need to rearrage the array.

I just added such a custom data source at the Support page.
Using thos functions, you can easilly merge your news with 2 MergeBlock() using sub-blocks.

$TBS->MergeBlock('main',$RssArray);
$TBS->MergeBlock('sub','nestedarray','RssArray[#%p1%][items]');

By: Werner
Date: 2004-08-27
Time: 22:23

Re: trouble with nested arrays

I'm sorry, but i still have problems to understand the Template part. I just started with tbs and this looks very advanced. I have look into tbs_us_examples_subblock.php and think i fully understand the example.

As far as i understand the main block walk through the items and the sub block walk through title and link (with a reference from main of the current item).
I have tried many diffrent ways, but everything is far away from my expected Output.

Btw, the Examples would be *much* more readable with less Markup. Sometimes nested tables are used only for Layout. Colors can be moved to the Basic Stylesheet.
Another Example:
<td width="30"><u>Position</u></td>
could be easier (and more w3c recommend) done with:
<td width="30">Position</th>

If you like, i can help to clean up the Examples.

Thanks,
Werner
By: Werner
Date: 2004-08-30
Time: 09:21

Re: trouble with nested arrays

I did it finaly with only 1 MergeBlock() call and without sub-blocks.
$TBS->MergeBlock('news',$RssArray['items']);

and the Template:
<h3>[var.RssArray.title]</h3>
<ul>
    <li><a href="[news.link;block=li]">[news.title]</a></li>
</ul>

However, it would be nice if you can add a example Template for your nestedarray Custom functions. I still want to know how it works :)

Thanks for your great support
Werner