View previous topic :: View next topic |
Author |
Message |
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 12:21 pm Post subject: loading Template through a Template |
|
|
hi there, i got a small problem (
i got a php file (index file) and another php file (where left and right boxes are generated)
and 2 templates ( 1 for the index file, and 1 for each included box).
now i got my index template, and want to include there my php file, wich generates the including code for each box ( and each box use a template of its own)
i include this file with {php} require('mybox.php'); {/php}
the file get loaded, but i just get an error.
Fatal error: Call to a member function on a non-object in mybox.php line 23
but, there is nothing special in line 23, only my adodb code
$box_align_query = $db->Execute("SELECT box_n.....
but there isnt any error if i include my php file wich generates the boxes in a normal .php file,
if i include this php file wich genereates the boxes in a template file, i got an error. ?!
any idea ? thx |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 04, 2003 12:36 pm Post subject: |
|
|
you don't have access to your global variables by default, when using {include_php}.
add on top of your included script. |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Sun May 04, 2003 1:17 pm Post subject: |
|
|
use
{include_php file="..."} instead of {php}...{/php}
there you can import your variables, like $db, into the local namespace using the command messju posted above |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 1:29 pm Post subject: |
|
|
ah right, i should read the doku better |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 1:31 pm Post subject: |
|
|
but, i have to include all vars like this ?
i got like 400 definition vars in 1 file, no other way ? |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Sun May 04, 2003 1:34 pm Post subject: |
|
|
$GLOBALS["varname"] |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 1:38 pm Post subject: |
|
|
no other way ?
cant define 400 vars as global in each file... |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 1:43 pm Post subject: |
|
|
Why aren't you using assign() from your main index to set-up the vars? |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 1:58 pm Post subject: |
|
|
cause, those definitions are in 2 files, and this files get loadet in every file,
and i cant assign all those vars, cause most can edited from my admin interface. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 04, 2003 2:25 pm Post subject: |
|
|
makes all your globals *readable*
if you need to those values *readable/writeable* do instead:
Code: | foreach(array_keys($GLOBALS) as $_var) $$_var =& $GLOBALS[$_var];
|
but this is a bad workaround, of course. consider rendering your boxes in global context and just assign the html-code they produce to $smarty. use output_buffering for that:
Code: |
ob_start();
require....;
$smarty->assign('boxes', ob_get_contents());
ob_end_clean();
$smarty->display('index.tpl'); // you can use {$boxes} in your template
|
if your boxes rely on 400 global variables *and* smarty-templates consider a major re-design. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 2:26 pm Post subject: |
|
|
so you don't intend to ever assign the vars? hmmm.
edit: just saw messju's post. I have to agree: it looks like you are trying it the hard way. |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 3:21 pm Post subject: |
|
|
if it would be that easy..
ok, i got my index.php
****
Code: |
require('includes/system.php');
require(DIR_WS_INCLUDES . 'header.php');
$smarty = new Smarty;
$smarty->cache_handler_func = 'xtcCacheHandler';
$smarty->assign('MAIN_CONTENT',....stuff for middlecontent');
$smarty->display('main_theme.html');
|
***
then i got my main theme.html
(table with 3 columns)
****
Code: |
{include_php file="includes/column_left.php"}
|
then my column_left.php
**
Code: |
global $db;
$box_align_query = $db->Execute("SELECT box_name FROM box_align WHERE box_align='left' AND box_visible='1'");
while ($box_align_values = $box_align_query->fields) {
require('includes/boxes/' . $box_align_values['box_name']);
$box_align_query->MoveNext();
}
|
then a box file (getting loaded with that require)
***
Code: |
global $db;
$smarty = new Smarty;
$smarty->cache_handler_func = 'xtcCacheHandler';
$box_content = my content....
$box_tpl_query = $db->Execute("SELECT box_align FROM " . $xtcDBTable['box_align'] . " WHERE box_name='loginbox.php'");
while ($box_tpl_values = $box_tpl_query->fields) {
$smarty->assign('BOX_TITLE', xtcTextTool::heading($lang['box_heading_members']));
$smarty->assign('BOX_TITLE_ALIGN', left);
$smarty->assign('BOX_CONTENT', $box_content);
$smarty->assign('BOX_CONTENT_ALIGN', left);
$smarty->display('box_'.$box_tpl_values['box_align'].'.html');
$box_tpl_query->MoveNext();
}
|
as u see, i got in db selects, links, etc , every vars like
. $lang['box_loginbox_email'] .
. $xtcDBTable['box_align'] .
and those are defined in a other php file. if i define those vars in my box file, it works, if not , it dont work.
so i got a big problem with all those defined vars. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 3:53 pm Post subject: |
|
|
okay--in your box files, what if they returned the appended results of a fetch() instead of using display... then column left uses $boxdata .= require (...) return the appended results ... then from index you $foo = include ('includes/column_left.php') and you have everything you need before you call display.
Just thinking out loud. Its a bit of a head scratcher |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 04, 2003 4:47 pm Post subject: |
|
|
well i tried it ~~ but ;/
{assign var=foo value="includes/column_left.php"}{include file=$foo}
in my main theme.
but smarty thinks thats column_left.php is an tpl resource, and look in templates/ for it. so i only get an error
Warning: Smarty error: unable to read template resource: "includes/column_left.php
if i give smarty the whole path to my column_left.php
another error.
Fatal error: Call to undefined function: () in H:\wampp2\htdocs\html\includes\classes\smarty\Smarty.class.php
***
then i tried to fetch the result of 1 box into a var, it worked, but vars still lost.
i think the problem is between my index template and the included php file wich generating including code for the box.php files.
cause if i call those box.php files (wich generating templates) from a normal php file, all definitions and vars still there, but not if i load the same file from a template file. ~~ kinda confusing problem, isnt it ? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 5:18 pm Post subject: |
|
|
sorry I meant $foo = include(..) from your index.php file
Probably still won't get you there. I'll think about it. |
|
Back to top |
|
|