[Typo3] call php variable from TS

Kraft Bernhard kraftb at gmx.net
Tue Feb 22 12:30:01 CET 2005


Mariagrazia Mazzanti wrote:
> I'd like to know, if it's possible, how to get the content of a php 
> variable from TS (template setup).
> This variable is set in an extension .php file and I'd want to print its 
> content in my template instead of styles.content.get, only in one page 
> of my site.

First of all you will need to make sure the variable is a global one.
if it's just visible in the scope of your method/function you will not
be able to access it ...

You can then use my extension kb_betterstdwrap to insert an arbitrary variable into
a TEXT type content object.

<phpscript.php>
function myMethod1() {
	globals $myvar;
	$myvar = 1;
}
or
function myMethod2() {
	$GLOBALS['myvar'] = 2;
}
</phpscript.php>


<TS-Setup>
temp.myobject = TEXT
temp.myobject.insertData = 1
temp.myobject.value = MyValue : {glob:myvar}
</TS-Setup>

if your myvar variable is an array or object you can access its variables
like this:

$myvar = array('fruit' => 'apple', 'vegetable' => 'carrot');

temp.myobject.value = MyValue : {glob:myvar:fruit}

will result in
MyValue : apple
in temp.myobject


greets,
Bernhard
-- 
Kraft Bernhard
MOKKA Medienagentur <http://www.mokka.at>
T: +43 - 1 - 895 33 33 - 50



More information about the TYPO3-english mailing list