0

Like to know if something like this is possible in php and how to do it.

I want to assign a tpl to the index page and when a button is clicked and index changes to signup i want to assing a different tpl

Something like this:

if('rendered_page' = signup.php){

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

{else} 

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

}

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

2 Answers2

0

Everything depends on your structure and your needs.

You can do it for example this way:

In PHP

<?php

$currentUrl = $_SERVER['REQUEST_URI'];

if($currentUrl == 'signup.php') { // notice that there are 2 = signs not one to compare

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

else {

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

}

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

In index.tpl

{$rendered_page}

But you can also do it this way (simple displaying template not fetching first):

In PHP

<?php

$currentUrl = $_SERVER['REQUEST_URI'];

if($currentUrl == 'signup.php') { // notice that there are 2 = signs not one to compare

$t->display('signup.tpl');

else {

$t->display('login.tpl');

}

The last option is putting this directly in Smarty template, so you can do it this way:

in PHP

<?php

$currentUrl = $_SERVER['REQUEST_URI'];
$t->assign('currentUrl', $currentUrl);
$t->display('index.tpl');

In index.tpl

{if $currentUrl eq 'signup.php'}
   {include 'signup.tpl'}
{else}
   {include 'login.tpl'}
{/if}
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
-1

From the description you provided I think You need to check what the current page is, it can be done by:

<?php
$currentpage = basename($_SERVER['PHP_SELF']);
?>

So your code will become:

<?php
$currentPage = basename($_SERVER['PHP_SELF']);

if($currentPage == "signup.php"){

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

}else{ 

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

}
?>
Qarib Haider
  • 4,796
  • 5
  • 27
  • 38