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

calling .php inside .tpl - check my code

 
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
whizz_kid
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Wed Aug 01, 2007 11:08 am    Post subject: calling .php inside .tpl - check my code Reply with quote

Hey guys, im having some real issues trying to call a .php file inside a .tpl file. Here is what i have so far; (pay particular attention to the bold bits as this is what i need help with) I ahve tried oter methods such as inserting php tags inside the .tpl and nothing has worked so far.

the php file
<?php
if ( !defined( 'SMARTY_DIR' ) ) {
include_once( 'init.php' );
}
$t->assign('lang',$lang);

$t->assign('conf', $_GET['conf']);

$t->assign('rendered_page', $t->fetch('confirmreg.tpl') );

$template->assign_vars(array(
'TESTME_INCLUDE' => implode("",file("http://www.mysite.com/templates/default/importer.php")),

$t->display( 'index.tpl' );
?>

.tpl file
{strip}
<form method="get" action="completereg.php">
<table border="0" cellpadding="0" cellspacing="0" width="571">
<tr>
<td width="100%" class="module_detail_inside" align="center">
{assign var="page_hdr01_text" value="{lang mkey='confirm_your_profile'}"}
{include file="page_hdr01.tpl"}
<table border="0" width="100%" cellpadding="{$config.cellpadding}" cellspacing="{$config.cellspacing}">
<tr>
<td width="100%">
<table cellpadding="5">
{if $conf == '1'}

<tr><td>{lang mkey='profile_auto_confirmed'}</td></tr>

{else}
{if $smarty.get.errid == '' }
<tr><td>{lang mkey='confirm_letter_sent'}</td></tr>

<tr><td align="center">{lang mkey='or'}</td></tr>

{else}
<tr><td>{lang mkey='wrong_activationcode'}</td></tr>

{/if}
<tr><td>{lang mkey='enter_confirm_code'}</td></tr>

<tr><td>
<input type="text" name="txtconfcode" size="40"/>
&nbsp;
<input type="submit" class="formbutton" value="{lang mkey='confirm_your_profile'}"/>
</td>
</tr>
{/if}
</table>
{TESTME_INCLUDE)
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
{/strip}
Back to top
View user's profile Send private message
DaKaLKa
Smarty Regular


Joined: 23 Apr 2006
Posts: 99
Location: Ketsch, Germany

PostPosted: Wed Aug 01, 2007 11:23 am    Post subject: Reply with quote

Try to use the include_php smarty function : http://smarty.php.net/manual/en/language.function.include.php.php

By the way, this is not a good template-design. I would prefer to never include any php-file in a template, because this really breaks the idea of templates Evil or Very Mad
Back to top
View user's profile Send private message
DaKaLKa
Smarty Regular


Joined: 23 Apr 2006
Posts: 99
Location: Ketsch, Germany

PostPosted: Wed Aug 01, 2007 11:28 am    Post subject: Reply with quote

Do you want do include the text of the php-File or execute the php-File like including it with include oder require in php?
Back to top
View user's profile Send private message
whizz_kid
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Wed Aug 01, 2007 11:32 am    Post subject: Reply with quote

I tried to use to the include php function and it wouldn't work. I want to actually execute the .php file.
Back to top
View user's profile Send private message
DaKaLKa
Smarty Regular


Joined: 23 Apr 2006
Posts: 99
Location: Ketsch, Germany

PostPosted: Wed Aug 01, 2007 12:35 pm    Post subject: Reply with quote

Ok, if you want to execute the script, then you just have to give the filename to the include_php-Smarty-function, e.g.

{include_php file="http://www.mysite.com/templates/default/importer.php"}

So you have to modify your php-script:
$template->assign_vars(array('TESTME_INCLUDE', "http://www.mysite.com/templates/default/inporter.php"));

and in the template :
{include_php file=$TESTME_INCLUDE}
Back to top
View user's profile Send private message
whizz_kid
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Wed Aug 01, 2007 4:48 pm    Post subject: Reply with quote

I get this error
Fatal error: Call to a member function on a non-object in /home/878/public_html/confirmreg.php on line 11
Back to top
View user's profile Send private message
DaKaLKa
Smarty Regular


Joined: 23 Apr 2006
Posts: 99
Location: Ketsch, Germany

PostPosted: Wed Aug 01, 2007 5:30 pm    Post subject: Reply with quote

Wow, this is a wonderful error-Message saying exactly what the error is. But without the line of code, in which the error occurs, it's hard to guess what the error could be Very Happy
But I try it :
Have you copy and paste my example, if yes : you have to modify it to use your own smarty-object.
I think this would help :
use :
$t->assign('TESTME_INCLUDE',"http://www.mysite.com/templates/default/inporter.php");
instead of
$template->assign_vars(array('TESTME_INCLUDE', "http://www.mysite.com/templates/default/inporter.php"));

And turn on all error-logs an warnings in php. This helps a lot !!!
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Aug 01, 2007 6:09 pm    Post subject: Reply with quote

When you use {include_php} (or {php} blocks) the target PHP code is executed in the context of the current Smarty object (in one of its methods). If your PHP code is relying on global variables, you'll have to import them.
Back to top
View user's profile Send private message
whizz_kid
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Wed Aug 01, 2007 9:57 pm    Post subject: Reply with quote

still not working - its just blank where its suppose to appear and isn't executing at all.
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
Page 1 of 1

 
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