Categories > TinyButStrong general >

Fields with parameters, which are an array of subarrays (many dots), do not work.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: desbest
Date: 2011-04-24
Time: 22:43

Fields with parameters, which are an array of subarrays (many dots), do not work.

Variables with parameters, which are an array of subarrays (many dots), do not work.
Here is my html code.
<tr>[basketitem;block=tr]
            <td>[basketitem.c1.itemid]
            <img src="[product.photopath;block=tr;p1=66]" style="max-width: 125px; max-height: 150px;"></td>
            <td>[product.title]
            <br>[variation.attribute;block=tr;p1=73]</td>
            <td>[basketitem.c[basketitem.#].quantity]</td>
            <td>[var.currencysign;htmlconv=no][product.quantity]</td>
            </tr>

On the 3rd line above, with the image, the parameter 1 (p1) is 66.
However, changing the field to any of the two below, cause the block to not work, as no parameter will be passed.
For both examples below, both variables are 66.
[product.photopath;block=tr;p1=[var.sixtysix]]

[product.photopath;block=tr;p1=[basketitem.c[basketitem.#].itemid]]

For my problem to be solved, I would love both examples to work at merging the blocks, preferably the 2nd one, because that's the one I want to work.
Right now, both fields FAIL at making the blocks merge, and it's as if TBS isn't reading those values to be 66, at all.

For further help for you, below is what the basketitem[] array is.
It runs with a basketitem[]c1[] hierachy, then the 5 elements below are in c1.
Array
(
    [0] => Array
        (
            [c1] => Array
                (
                    [itemid] => 66
                    [variationid] => 73
                    [quantity] => 1
                    [itemid_pre] => i66
                    [variationid_pre] => v73
                )

        )

)
By: Skrol29
Date: 2011-04-25
Time: 22:05

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Hi Debest,

This is a problem of precedence of the merges.

[product.photopath;block=tr;p1=[var.sixtysix]]
[var] fields are merged at the end of the merge, during the Show() method. (expect for few TBS parameters).
So, [var.sixtysix] is not merged yet when you try to merge the "product" block.

[product.photopath;block=tr;p1=[basketitem.c[basketitem.#].itemid]]
The same here. You have to merge block "basketitem" before block "product" to have this working.
And [basketitem.c[basketitem.#].itemid] will probably cause a problem because they are two fields of the same block which are embedded.
By: desbest
Date: 2011-04-25
Time: 22:27

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

How else can I loop through arrays without using [basketitem.c[basketitem.#].itemid]?
The # is needed, as it makes the array shown move from 1, 2 and 3 etc.
The [basketitem] array has no keys and values, as it contains an array called c1.
I'm making a shopping cart, so that's why I have a multidimensional array, the way it is.

How else can I move from c1 and c2, without the hash? Are there any workarounds I can use?
By: Skrol29
Date: 2011-04-25
Time: 22:57

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

> The [basketitem] array has no keys and values, as it contains an array called c1.

Can you give an example of "basketitem" when they are several products in the basket ?
By: desbest
Date: 2011-04-25
Time: 23:03

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Array
(
    [0] => Array
        (
            [c1] => Array
                (
                    [itemid] => 70
                    [variationid] => 76
                    [quantity] => 1
                    [itemid_pre] => i70
                    [variationid_pre] => v76
                )

            [c2] => Array
                (
                    [itemid] => 66
                    [variationid] => 73
                    [quantity] => 1
                    [itemid_pre] => i66
                    [variationid_pre] => v73
                )

        )

)
By: Skrol29
Date: 2011-04-25
Time: 23:32

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Why don"t you simply merge the block "basketitem" with $basketitem[0] instead of $basketitem ?
By: desbest
Date: 2011-04-26
Time: 00:09

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

That's sadly not possible, because php's print_r function shows a [0] to introduce an array, and does not represent a suffix to an array that can be viewed.

Here's the code I do have.
$basketitem[] = $_SESSION['basket']['items'];
$TBS->MergeBlock('basketitem','array',$basketitem);

Below is code that causes it not work when I use print_r($basketitem);
Using that, print_r shows nothing.
$basketitem[] = $_SESSION['basket']['items']['0'];
By: Skrol29
Date: 2011-04-26
Time: 00:12

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Why don"t you replace:
$basketitem[] = $_SESSION['basket']['items'];
with:
$basketitem = $_SESSION['basket']['items'];
and then you will have no $basketitem[0] level, but $basketitem['c1'], $basketitem['c2'], ...
By: desbest
Date: 2011-04-26
Time: 00:14

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Thanks alot for your help. You've made php coding a lot easier for me. I've never worked with arrays before. Thanks a lot.
By: desbest
Date: 2011-04-27
Time: 15:13

Re: Fields with parameters, which are an array of subarrays (many dots), do not work.

Yes it actually works now. TBS really does loop through the [basketitem] array now, and I got parameters to work.
Is there anything that TBS can't do? XD