Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

loading Template through a Template
Goto page 1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 12:21 pm    Post subject: loading Template through a Template Reply with quote

hi there, i got a small problem Smile(

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
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 04, 2003 12:36 pm    Post subject: Reply with quote

you don't have access to your global variables by default, when using {include_php}.

add
Code:
global $db;
on top of your included script.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Sun May 04, 2003 1:17 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 1:29 pm    Post subject: Reply with quote

ah right, i should read the doku better Very Happy
Back to top
View user's profile Send private message Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 1:31 pm    Post subject: Reply with quote

but, i have to include all vars like this ?
i got like 400 definition vars in 1 file, no other way ?
Back to top
View user's profile Send private message Visit poster's website
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Sun May 04, 2003 1:34 pm    Post subject: Reply with quote

$GLOBALS["varname"]
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 1:38 pm    Post subject: Reply with quote

no other way ?
cant define 400 vars as global in each file...
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 1:43 pm    Post subject: Reply with quote

Why aren't you using assign() from your main index to set-up the vars?
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 1:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 04, 2003 2:25 pm    Post subject: Reply with quote

Code:
 extract($GLOBALS);

makes all your globals *readable* Smile

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
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 2:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 3:53 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 04, 2003 4:47 pm    Post subject: Reply with quote

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 ? Very Happy
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 5:18 pm    Post subject: Reply with quote

sorry I meant $foo = include(..) from your index.php file Smile

Probably still won't get you there. I'll think about it.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP