Categories > TinyButStrong general >

I need help retrieving 3 dimensional arrays through subblocks of subblocks while referencing by arra...

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: David Dodson
Date: 2017-03-10
Time: 16:25

I need help retrieving 3 dimensional arrays through subblocks of subblocks while referencing by array keys

I have been trying to figure out how to solve this problem and am at a loss.

The long version with more context is at the bottom of this.

The short version: How do I handle looping through a subblock of a subblock and referencing the variables in an array by their keys at the lowest level? Bonus if it does not have anything to do with referencing any HTML tags.

Example with information to be displayed from a list of two people:

    [LIST2] => Array(
            [0] => Array(
                    [BIO2] => Array(
                            [0] => Array(
                                    [NAME] => Geoffrey Burton
                                    [TITLE] => Jhon Balance
                                    [LINES] => It's only lightening, teenage lightning
                                    [PARAGRAPHS] => One step... two... three...
                                    [IMAGE] => <img src="mud.png" alt="showing his hand" border="0">)))
            [1] => Array(
                    [BIO2] => Array(
                            [0] => Array(
                                    [NAME] => Charles Ridenhour
                                    [TITLE] => Mr. Chuck
                                    [LINES] => The voice of choice
                                    [PARAGRAPHS] => Bass, how low can you go<br> etc.
                                    [IMAGE] => PE target logo))))

I have tried all of these approaches with no luck (the outer list loops, but I still can not retrieve the inner list's data):

[LIST2;block=begin;sub1=BIO2]
    <tr><td bgcolor="#ff00ff">
      [LIST2.#;sub1=BIO2]
      [LIST2.BIO2.IMAGE]
      [LIST2.BIO2.IMAGE;val]
      [onshow.LIST2.BIO2.IMAGE]
      [onshow.LIST2.BIO2.IMAGE;val]
      [LIST2_sub1.val]
      </td>
    </tr>
[LIST2;block=end]

Please help,
David


The long version:  I am creating a document template manager that involves the following process:

1] Someone that is not expected to know anything more than HTML and the doc that I give them to follow, creates a TBS template that is restricted to following my conventions.  These conventions include a list of variable names that are pre-defined for all BIO info coming from a repository.

2] The document is placed in a location where it will be scraped for TBS variables.

3] TBS variable names, per my instructions, start with key words that will be picked up to determine what type of data is to be expected.  The type of data is loaded into a related template database.

Note] for simple html, [onshow.PAGETITLE] is easy to display, but the more complex data handling, especially blocks within blocks, has become much more challenging.  A common need for this is if we have a list of people that are to be displayed with cherry picked variables (i.e. name and title, but not photo or bio - it all comes from the same query, so all of the data will be passed to the page, and the TBS variables that are in the source template will be the only ones that are displayed).

4] Default variables are loaded when a new template version is being created.

5] An edit screen replaces all TBS variables with form fields, date pickers, lists of options, etc. based upon the type of data that was scraped in step 3.  When saved, the necessary data is stored for viewing the resulting document or duplicating it as a starting point for an alternative version (instead of starting with default variables).

6] In the case that BIO data is loaded, the only thing that is stored is a database key which will retrieve all relevant information.  If a list of presenters is needed (as will be the case often), then the data structure that is shown above will be created and I will need to loop through and reference the Name, Title, etc. directly for each person.



By: Skrol29
Date: 2017-03-12
Time: 00:04

Re: I need help retrieving 3 dimensional arrays through subblocks of subblocks while referencing by array keys

Hi David,

May it has several items under a BIO2? In you two examples, there is only one.

Can you give an example of result to try to have ?



By: David Dodson
Date: 2017-03-13
Time: 15:07

Re: I need help retrieving 3 dimensional arrays through subblocks of subblocks while referencing by array keys

>Can you give an example of result to try to have ?

Here you go:

   [LIST2] => Array(
            [0] => Array(
                    [BIO2] => Array(
                            [0] => Array(
                                    [NAME] => Geoffrey Burton
                                    [TITLE] => Jhon Balance
                                    [LINES] => It's only lightening, teenage lightning
                                    [PARAGRAPHS] => Jhon Balance is the founder of the band COIL as well as a past member of the band PSYCHIC TV.  In his youth....
                                    [IMAGE] => <img src="mud.png" alt="showing his hand" border="0">)))
            [1] => Array(
                    [BIO2] => Array(
                            [0] => Array(
                                    [NAME] => Charles Ridenhour
                                    [TITLE] => Chuck D
                                    [LINES] => The voice of choice
                                    [PARAGRAPHS] => Chuck D, the front man and lead emcee of the legendary hiphop band Public Enemy began producing music...
                                    [IMAGE] => <img src="pe.gif" alt="target logo" border="0">)))
            [3] => Array(
                    [BIO2] => Array(
                            [0] => Array(
                                    [NAME] => Eric Boucher
                                    [TITLE] => Jello Biafra
                                    [LINES] => I am your clock
                                    [PARAGRAPHS] => During his Mayoral campaign, the former lead singer for the punk rock band, the Dead Kennedys, and current front man for Ministry side project LARD, came in fourth place against...
                                    [IMAGE] => <img src="DK.gif" alt="The power of Lard" border="0">))))

The template concept A:

<table>
     <tr>
          <td colspan="2">Our guest speakers:</td>
     </tr>
     [begin loop]
     <tr>
          <td>[BIO2.0.IMAGE]</td>
          <td>Please welcome [BIO2.0.NAME], a.k.a. [BIO2.0.TITLE]<br>
               [BIO2.0.LINES]
          </td>
     </tr>
     [end loop]
</table>

//note that [BIO2.0.PARAGRAPHS] is sent data that in this case is never used.  The data for all BIO fields is always sent, but the template designers can use or discard any variable that is in a BIO.

Template concept B:

<div>[TITLE]<br>
[PARAGRAPHS]
</div>

//note that this time all but two fields are discarded.


The desired result A:

<table>
     <tr>
          <td colspan="2">Our guest speakers:</td>
     </tr>
     <tr>
          <td><img src="mud.png" alt="showing his hand" border="0"></td>
          <td>Please welcome Geoffrey Burton, a.k.a. Jhon Balance<br>
               It's only lightening, teenage lightning
          </td>
     </tr>
     <tr>
          <td><img src="pe.gif" alt="target logo" border="0"></td>
          <td>Please welcome Charles Ridenhour, a.k.a. Chuck D<br>
               The voice of choice
          </td>
     </tr>
     <tr>
          <td><img src="DK.gif" alt="The power of Lard" border="0"></td>
          <td>Please welcome Eric Boucher, a.k.a. Jello Biafra<br>
               I am your clock
          </td>
     </tr>
</table>


The desired result B:

<div>Jhon Balance<br>
Jhon Balance is the founder of the band COIL as well as a past member of the band PSYCHIC TV.  In his youth....
</div>

<div>Chuck D<br>
Chuck D, the front man and lead emcee of the legendary hiphop band Public Enemy began producing music...
</div>

<div>Jello Biafra<br>
During his Mayoral campaign, the former lead singer for the punk rock band, the Dead Kennedys, and current front man for Ministry side project LARD, came in fourth place against...
</div>

NOTE: I could adjust the data structure, but, the most important thing is that this is a list of bios with a bio being an array that includes all fields from a query based upon a primary key of the person.  I need to have the BIO key start with the word BIO for the data to be recognized as a BIO when the template file is scraped into the database.

An alternate way to show the data could potentially be:

   [LIST2] => Array(
            [0] => Array(
                    [BIO2] => Array(
                                    [NAME] => Geoffrey Burton
                                    [TITLE] => Jhon Balance
                                    [LINES] => It's only lightening, teenage lightning
                                    [PARAGRAPHS] => Jhon Balance is the founder of the band COIL as well as a past member of the band PSYCHIC TV.  In his youth....
                                    [IMAGE] => <img src="mud.png" alt="showing his hand" border="0">)))
            [1] => Array(
                    [BIO2] => Array(
                                    [NAME] => Charles Ridenhour
                                    [TITLE] => Chuck D
                                    [LINES] => The voice of choice
                                    [PARAGRAPHS] => Chuck D, the front man and lead emcee of the legendary hiphop band Public Enemy began producing music...
                                    [IMAGE] => <img src="pe.gif" alt="target logo" border="0">)))
            [3] => Array(
                    [BIO2] => Array(
                                    [NAME] => Eric Boucher
                                    [TITLE] => Jello Biafra
                                    [LINES] => I am your clock
                                    [PARAGRAPHS] => During his Mayoral campaign, the former lead singer for the punk rock band, the Dead Kennedys, and current front man for Ministry side project LARD, came in fourth place against...
                                    [IMAGE] => <img src="DK.gif" alt="The power of Lard" border="0">))))

By: Skrol29
Date: 2017-03-13
Time: 22:53

Re: I need help retrieving 3 dimensional arrays through subblocks of subblocks while referencing by array keys

Hi,

I'm sorry but I'm a bit lost with your question.

For the desired result A, the template could be:
<table>
     <tr>
          <td colspan="2">Our guest speakers:</td>
     </tr>
     <tr>
          <td>[LIST2.BIO2.0.IMAGE;strconv=no;block=tr]</td>
          <td>Please welcome [LIST2.BIO2.0.NAME], a.k.a. [LIST2.BIO2.0.TITLE]<br>
               [LIST2.BIO2.0.LINES]
          </td>
     </tr>
</table>

Of course this can be a bit complicated if such a template has to be designed by "Someone that is not expected to know anything more than HTML".
Bu for such cases, I usually give to the user a simple syntax for fields (for example "[IMAGE]", "[TITLE]", ....) and when I load the template, just before doing the MergeBlock(), I do a str_replace()
to convert "[IMAGE]" into "[LIST2.BIO2.0.IMAGE]", and the same for other fields.
It's also simple to insert ";block=tr" for only one field when necessary.
And you can of course use the explicit syntax instead. For example: [BIO_START] will be replaced with "[LIST2;block=begin]", and "[BIO_END]" with "[LIST2;block=end]"


For the desired result B, the template could be:
<div>[LIST2.BIO2.0.TITLE]<br>
[LIST2.BIO2.0.PARAGRAPHS]
</div>