Help with smarty??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
indyonline
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2008 8:20 pm

Help with smarty??

Post by indyonline »

Hello everyone. I have a game site script I bought that was writen with smarty.
I was wanting to add some advertisement to one single page but it shows up in every page.
I created the file test.tpl and added this code in the layout.tpl

Code: Select all

<div>{include file="test.tpl"}</div>
Does anybody know a way to edit this code to make it only show the ad on the index.html page?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Help with smarty??

Post by novice4eva »

Why don't you simply put a condition like:
In PHP, in index.php(or the page you want to show add):

Code: Select all

 
$smarty->assing('showAdd',1);
 
and in the template , just a simple check

Code: Select all

 
{if $showAdd eq 1}
{include file="yourAdd.tpl"}
{/if}
 
indyonline
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2008 8:20 pm

Re: Help with smarty??

Post by indyonline »

I have another ad that needs to go in an internal page. I was asking the way I did cause I was hoping there was a code that would include the page name so I could change it also to go on that page. something that would include the page name like-- "/folder/page.tpl"

would it work the same way?

In my file manager the index.html page is an application. the changes I gotta make for the main page I have had to do in the "layout.tpl" page.



would this work in the layout.tpl page?

Code: Select all

# {if $showAdd eq "index.html"}
# {include file="yourAdd.tpl"}
# {/if}
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Help with smarty??

Post by novice4eva »

sorry i didn't get what are trying to achieve, could you elaborate a bit. Do you mean that you have editing access to only template files??
indyonline
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2008 8:20 pm

Re: Help with smarty??

Post by indyonline »

ya, in the file manager ther is an index.html page but it is an application and it only has DB info on it. If I add anything to it it doesn't show. if I go to /template/default/layout.tpl thats where I can add stuff and it shows up on the site. I created a file named test.tpl and include the code
<div>{include file="footer.tpl"}</div>
it shows the ad on every page. I want to add it to an internal page only. (that I can edit to include on other internal pages too)
I figured it would be something like this (dont laugh I'm not good at php)
{if "/internalpage.html" include file= "test.tpl"}{/if}
something like that
indyonline
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2008 8:20 pm

Re: Help with smarty??

Post by indyonline »

there is also an index.tpl file ( /templates/default/index.tpl )but I cant add anything to it and it show up on the site.

Code: Select all

<table cellpadding="0" cellspacing="0" border="0" width="578" align="center">
  <tr>
    <td>
      <table cellpadding="0" cellspacing="4" border="0">
        {foreach name=row_cat_center from=$Rows_Cat_Center item="cat_center_row"}
        {if $smarty.foreach.row_cat_center.iteration%2==1  || $smarty.foreach.row_cat_center.first}
        <tr> {/if}
          <td valign="top">
            <table cellpadding="0" cellspacing="0" border="0" width="287" class="box1">
              <tr>
                <td background="{$T_Images_Tpl}bar2.gif" height="31" width="287" class="boxtit"><a class="category" title="{$cat_center_row.category_title|escape|trim}" href="{$cat_center_row.sef_url}">{$cat_center_row.category_title|escape|trim} ({$cat_center_row.games_count|default:0}) </a></td>
              </tr>
              <tr>
                <td> {if $cat_center_row.games|@count >= 1 }
                  {foreach name=row_game from=$cat_center_row.games item="game_row"}
                  <table width="282" border="0" cellspacing="5" cellpadding="0">
                    <tr>
                      <td width="60" valign="top"><a href="{$game_row.sef_url|trim}" title="{$game_row.game_title|escape|trim}"><img border="0" src="{$Site_Url}libs/phpthumb/phpThumb.php?src={$Game_Images}{$game_row.game_image}&w=60&h=60&iar=1" height="60" width="60" alt="{$game_row.game_title|escape|trim}" /></a></td>
                      <td valign="top"><span class="boxtext"><a href="{$game_row.sef_url|trim}" title="{$game_row.game_title|escape|trim}">{$game_row.game_title|escape|trim}</a></span><br>
                        <div class="boxdesc">{$game_row.game_description|escape|trim}</div></td>
                    </tr>
                  </table>
                  {/foreach}
                  {else}
                  <table width="282" border="0" cellspacing="5" cellpadding="0">
                    <tr>
                      <td><span class="boxdesc">No games in this category.</span></td>
                    </tr>
                  </table>
                  {/if} </td>
              </tr>
            </table>
          </td>
          {if $smarty.foreach.row_cat_center.iteration%2==0 || $smarty.foreach.row_cat_center.last} </tr>
        {/if}
        {/foreach}
      </table>
    </td>
  </tr>
</table>
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Help with smarty??

Post by novice4eva »

HUmmmm this then

Code: Select all

 
{if $smarty.server.PHP_SELF eq 'internalpage.html'}
{include file="yourAdd.tpl"}
{/if}
 
but first check the $smarty.server.PHP_SELF value, it would be something lengthier. Hope it helps!
indyonline
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2008 8:20 pm

Re: Help with smarty??

Post by indyonline »

Ya, I get errors when I add that to the file.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Help with smarty??

Post by RobertGonzalez »

Create an app wide var that contains the name of your page. Then you can check to see if the page is 'index.php' or something else and show what you want depending on that.

Code: Select all

<?php
// You might need to check this server var to make sure it is the right index
// You can do a var_dump($_SERVER) to see which it should be
$smarty->assign('pagename', strtolower(basename($_SERVER['SCRIPT_NAME'])));
?>
[smarty] {if $pagename == 'index.php'}<!-- Show your index stuff here -->{else}<!-- show the not index stuff here -->{/if} [/smarty]
Post Reply