View previous topic :: View next topic |
Author |
Message |
whizz_kid Smarty Rookie
Joined: 01 Aug 2007 Posts: 5
|
Posted: Wed Aug 01, 2007 11:08 am Post subject: calling .php inside .tpl - check my code |
|
|
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"/>
<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 |
|
DaKaLKa Smarty Regular
Joined: 23 Apr 2006 Posts: 99 Location: Ketsch, Germany
|
|
Back to top |
|
DaKaLKa Smarty Regular
Joined: 23 Apr 2006 Posts: 99 Location: Ketsch, Germany
|
Posted: Wed Aug 01, 2007 11:28 am Post subject: |
|
|
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 |
|
whizz_kid Smarty Rookie
Joined: 01 Aug 2007 Posts: 5
|
Posted: Wed Aug 01, 2007 11:32 am Post subject: |
|
|
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 |
|
DaKaLKa Smarty Regular
Joined: 23 Apr 2006 Posts: 99 Location: Ketsch, Germany
|
Posted: Wed Aug 01, 2007 12:35 pm Post subject: |
|
|
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 |
|
whizz_kid Smarty Rookie
Joined: 01 Aug 2007 Posts: 5
|
Posted: Wed Aug 01, 2007 4:48 pm Post subject: |
|
|
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 |
|
DaKaLKa Smarty Regular
Joined: 23 Apr 2006 Posts: 99 Location: Ketsch, Germany
|
Posted: Wed Aug 01, 2007 5:30 pm Post subject: |
|
|
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
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Aug 01, 2007 6:09 pm Post subject: |
|
|
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 |
|
whizz_kid Smarty Rookie
Joined: 01 Aug 2007 Posts: 5
|
Posted: Wed Aug 01, 2007 9:57 pm Post subject: |
|
|
still not working - its just blank where its suppose to appear and isn't executing at all. |
|
Back to top |
|
|