Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
(ASK) TPL Element exception in selected page

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 12:32 pm    Post subject: (ASK) TPL Element exception in selected page Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7036
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 26, 2012 12:33 pm    Post subject: Reply with quote

assign a $page variable, then:

{if $page neq "foo"}hide this text from page foo{/if}
Back to top
View user's profile Send private message Visit poster's website
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 12:45 pm    Post subject: Reply with quote

@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
View user's profile Send private message
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 1:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7036
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 26, 2012 1:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 1:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7036
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 26, 2012 2:43 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 3:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 3:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7036
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 26, 2012 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7036
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 26, 2012 6:00 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
unapzeus
Smarty Rookie


Joined: 26 Jul 2012
Posts: 10

PostPosted: Thu Jul 26, 2012 7:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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