Using vars defined in php inside tpl files

175 views
Skip to first unread message

Yahav

unread,
Sep 16, 2012, 5:28:49 AM9/16/12
to phps...@googlegroups.com
Hello,

I've been planing to rewrite my projects to use Savant for a while now,
only thing is, i can't seem to use vars defined in the php file directly at the tpl files, etc:

 
 
//index.php
<?
...
$a = 'a';
...
$tpl->display('index.tpl.php');
?>

// index.tpl.php
<?
echo $a;
?>

any idea how can i achieve this?

Thanks.

Brett Bieber

unread,
Sep 16, 2012, 12:02:54 PM9/16/12
to phps...@googlegroups.com


On Sun, Sep 16, 2012 at 4:28 AM, Yahav <yahav....@gmail.com> wrote:
Hello,

I've been planing to rewrite my projects to use Savant for a while now,
only thing is, i can't seem to use vars defined in the php file directly at the tpl files, etc:

 
 
//index.php
<?
...
$a = 'a';
...
$tpl->display('index.tpl.php');
?>

// index.tpl.php
<?
echo $a;
?>

The issue here is a question of scope. The $a variable is declared inside a different scope and will not be available within the template file.

With Savant3, your best bet is to assign what you need before displaying the template OR define a helper which will be available everywhere.

The next-generation of Savant: Savvy and PEAR2_Templates_Savant, allow you to specify global variables available within every template. You might try using Savvy or PEAR2_Templates_Savant.


Hope that helps.

--
Brett Bieber
Reply all
Reply to author
Forward
0 new messages