Categories > TinyButStrong general >

Populating template values with Object Values-How?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: billray
Date: 2006-02-23
Time: 23:24

Populating template values with Object Values-How?

I have a complex object generated by mySQL that is created and managed outside of TBS.  The object has a number of sub-objects.  I would  like to pass some of these object values to a TBS template. but I get the following error:

Array value: Can't merge [listing.title] because sub-item 'title' is not an existing key in the array.

The call looks  something  like this:
$tbs->MergeBlock('listing',$fbdb->theFeed->items)
where items is another object.

I am assuming that TBS is looking for an array - is this correct? and if so is there anyway around it. 

Thanx in advance.
By: Skrol29
Date: 2006-02-24
Time: 01:33

Re: Populating template values with Object Values-How?

Hello Billray;

Yes, TBS is expecting an array or an id for a custom data source.

If the array is not an "array of array" { that is an array builing like = array( array(a,b,c), array(d,e,f,) ... ) } then you have to access to values in a TBS field using the virtual column named "val". In you case, values are objects, so (assuming that $fbdb->theFeed->items contains an array of objects having an existing property or method called "title") your TBS field should be:
  [listing.val.title]

I know this is not smart. Values of object properties should be displayed the same way as for columns or a record. I'll try to arrange that. But the issue I just give above should work for now.
By: billray
Date: 2006-02-24
Time: 02:51

Re: Populating template values with Object Values-How?

Thank you for the fast response...

On the HTML side - naturally I need to loop through the array of item objects, but I'm confused on the proper syntax.  I'm just looking to put together an unordered list of the items.

What should the html syntax be?

Thank you in advance.
By: Skrol29
Date: 2006-02-24
Time: 11:27

Re: Populating template values with Object Values-How?

I'm not sure to well understand your question.

Example if your source is an array of objects:
<tr><td>[listing.val.title;block=tr]</td><td>[listing.val.cost]</td></tr>

Example if your source is an array of array:
<tr><td>[listing.title;block=tr]</td><td>[listing.cost]</td></tr>
By: billray
Date: 2006-02-24
Time: 15:08

Re: Populating template values with Object Values-How?

I've figured most of it out.  I'm still very confused about the specifics of the mergeBlock syntax.  So far I've got

<ul>
      <li id="[listing.val.itemID;block=li]">
          <a href="[listing.val.link;block=li]"[var.target]>[listing.val.title;block=li]</a>
         <br />[listing.val.description;block=li]
    </li>
</ul>

I'd like to give the ul tag a unique ID, but I haven't figured that out yet.   I seem to be repeating the UL /UL tags over and over.
By: Skrol29
Date: 2006-02-24
Time: 16:13

Re: Populating template values with Object Values-How?

Hello Billray,

This is just a remak: you don't need to define "block=li" for all fields of the block. Only one is enougth to define the block bound. Any of them.

Example :
<ul>
   <li id="[listing.val.itemID;block=li]">
    <a href="[listing.val.link]"[var.target]>[listing.val.title]</a>
   <br />[listing.val.description]
</li>
</ul>

You can't reach the <ul> tags with this snippet because they are out of the block.
By: thuc101
Date: 2006-07-01
Time: 11:58

Re: Populating template values with Object Values-How?

Hello, Skrol29, this article is good for me. Thank you!!!