| View previous topic :: View next topic |
| Author |
Message |
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 12:32 pm Post subject: (ASK) TPL Element exception in selected page |
|
|
Hi, let me to asking some question about smarty tags on tpl file. It's about displaying element exception in some page.
Ex: i have global include file that be shown on all pages. But for some reason, i want to hide some element to selected page.
Please review my tags:
HEADER.TPL
<div>THIS GLOBAL ELEMENT</div>
<div>THIS SIDEBAR (I WILL DISPLAY ONLY FOR CONTACT PAGE)</div>
<div class="main">
Last edited by unapzeus on Thu Jul 26, 2012 12:37 pm; edited 1 time in total |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 26, 2012 12:33 pm Post subject: |
|
|
assign a $page variable, then:
{if $page neq "foo"}hide this text from page foo{/if} |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 12:45 pm Post subject: |
|
|
@mohrt, thanks for your fast reply. but i haven't done with my post (i am mobile). Ok, next i do this for HEADER.TPL
<div>THIS GLOBAL ELEMENT</div>
{if $page == 'CONTACT'}
<div>THIS SIDEBAR </div>
{/if}
<div class="main">
I tryin this method for several time, but i dont luck. How to solving my problems? thanks in advance |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 12:55 pm Post subject: |
|
|
Then in CONTACT.TPL and SUPPORT.TPL
{include file='HEADER.TPL'}
And i want get diferent results:
Sidebar will shown on CONTACT, and not visible on SUPPORT or other pages.
It will help me to have only 1 include file, but in diferent result of each pages.
Thank you |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 1:03 pm Post subject: |
|
|
| mohrt wrote: | assign a $page variable, then:
{if $page neq "foo"}hide this text from page foo{/if} |
And what tags to do "SHOW this text for page foo"? That's i mean. Thanks |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 26, 2012 1:15 pm Post subject: |
|
|
| unapzeus wrote: | | And what tags to do "SHOW this text for page foo"? That's i mean. Thanks |
Well, then you test if you are on that page instead of not on that page.
{if $page eq "foo"}show this text on page foo{/if} |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 1:48 pm Post subject: |
|
|
| mohrt wrote: |
{if $page eq "foo"}show this text on page foo{/if} |
Great! i will try this soon, cuz i have no luck with these tags before ask here.
Tried tags but no result :
{if $page eq 'CONTACT'} element {/if}
{if $page == 'CONTACT'} element {/if}
Hope my error's on single quoted. |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 26, 2012 2:43 pm Post subject: |
|
|
did you assign the $page value in PHP? example:
$smarty->assign('page','CONTACT');
of course, this needs to happen on each page with the correct values. |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 3:03 pm Post subject: |
|
|
| mohrt wrote: | did you assign the $page value in PHP? example:
$smarty->assign('page','CONTACT');
of course, this needs to happen on each page with the correct values. |
Of course i know. Cuz my site is runing between php and tpl.
Btw, tags above still not work for me.
I've placed exception element in include file (HEADER.TPL) where HEADER.TPL will included in all of my site pages. I just wondering why this problem's happen. |
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 3:36 pm Post subject: |
|
|
Uh oh, sorry. It's my mistake.
Please corret this:
<?php
$page = 'CONTACT';
include 'HEADER.php';
$smarty->assign('CONTACT',$CONTACT);
include 'FOOTER.php';
?>
Please see on my assign value and tell me to make {if $page eq "CONTACT"} BLA {/if} working properly.
I am here waiting ur answer. thanks |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 26, 2012 5:57 pm Post subject: |
|
|
This:
$smarty->assign('CONTACT',$CONTACT);
change to:
$smarty->assign('page',$page);
also, why include header.php and footer.php, shouldn't you do that in templates? |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 26, 2012 6:00 pm Post subject: |
|
|
I would do something like:
| Code: | $smarty = new Smarty();
$smarty->assign('page','mypage');
$smarty->display('index.tpl'); |
index.tpl:
| Code: | {include file="header.tpl"}
this page is {$page}
{include file="footer.tpl"} |
|
|
| Back to top |
|
unapzeus Smarty Rookie
Joined: 26 Jul 2012 Posts: 10
|
Posted: Thu Jul 26, 2012 7:08 pm Post subject: |
|
|
i'm new on smarty, and will using it for future. some big mistake may come to me, but i'll always
learning here cuz i've loved this.
well, back to topic. i found this one:
HEADER.php
| Code: |
if(in_array($page,array('CONTACT')))
{$smarty->assign('unapzeus',true);}
|
HEADER.tpl
| Code: |
{if $unapzeus}
exception element
{/if}
|
are these correct tags to answer my question?
thank you |
|
| Back to top |
|
|