Categories > TinyButStrong general >

conditional display of multidimensional array value

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Youri
Date: 2008-02-05
Time: 16:44

conditional display of multidimensional array value

Hi,

how can I conditionally display block based on a value stored in multidimenstional array?

ex.
<title>domain.tld - [var._SESSION[profile.account]]</title>

I have the user account info stored in $_SESSION['profile']['account']. It can be done via passing the value for ex. to $profile_account, but I have more parameters in $_SESSION['profile'] array, so assigning to temp variables is not much comfortable.

I have tried var._SESSION.profile.name but it does not work because TBS expects profile to be the key not array.

Thanks.
By: TomH
Date: 2008-02-05
Time: 18:27

Re: conditional display of multidimensional array value

try
extract("$_SESSION");
to see if you can get to
[var.profile.account]
By: Youri
Date: 2008-02-05
Time: 19:13

Re: conditional display of multidimensional array value

Thanks Tom,

Tried following test:

php:
$_SESSION['profile']['name'] = "test";

template:
<title>domain.tld - [var.profile.name]</title>

result:
TinyButStrong Error in field [var.profile.name...] : the PHP global variable named 'profile' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

session variables are generally accessible only from php, I can't get them work from TBS, even if it is only one dimensional array like $_SESSION['profile']. Any idea?
By: TomH
Date: 2008-02-05
Time: 19:41

Re: conditional display of multidimensional array value

The code you show does not seem to provide an array for TBS.

The suggestion to "extract" was made hoping that PHP would produce the result $profile as an array -- then you would be able to feed it to TBS directly.

You might test the contents of _SESSION with
$dump = print_r($_SESSION,true);

then
[var.dump]
to see what's actually in there
By: Skrol29
Date: 2008-02-06
Time: 00:13

Re: conditional display of multidimensional array value

hi Youri,

In your first post, the field [var._SESSION.profile.account] should work.
If it doesn't, look at the TBS error message and check the key it is talking about.
TBS does merge subitems.
By: Youri
Date: 2008-02-06
Time: 01:05

Re: conditional display of multidimensional array value

Thanks Skrol,

I've tried to put $_SESSION['profile']['test'] = "test"; at the beginning of the script. This is only for testing and is not changed or reseted later in the script.
In my template there is: <title>[var._SESSION.profile.test]</title>

and error message is:
TinyButStrong Error in field [var._SESSION.profile.test...] : item before 'test' is neither an object nor an array. Its type is string. This message can be cancelled using parameter 'noerr'.

But when I assign array like:
$_SESSION['profile']=array("test" => "test");
it works. Can I assign value to that array somehow less explicit than in the last example?
By: Youri
Date: 2008-02-06
Time: 01:18

Re: conditional display of multidimensional array value

Hmm,

blood simple: $_SESSION[profile][test] = "test";

- sorry for bothering you with PHP array basics....