Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{if} {else} help

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
whatshakin
Smarty n00b


Joined: 24 Sep 2009
Posts: 3

PostPosted: Thu Sep 24, 2009 2:13 pm    Post subject: {if} {else} help Reply with quote

I want to be able to show different content on the index page than the other pages. Is there an {if}{else} statement i can use to either include div's containing pictures or some modules based on the url? or is there another way?

Last edited by whatshakin on Thu Sep 24, 2009 3:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Thu Sep 24, 2009 3:01 pm    Post subject: Reply with quote

Smarty knows most server vars for url operations too - please make a look

http://www.smarty.net/manual/en/language.variables.smarty.php
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Sep 24, 2009 3:13 pm    Post subject: Reply with quote

does the urlExists plugin exist? If you have a value in $urlExists var, you can test it:

Code:
{if !empty($urlExists)}


Code:
{if $urlExists ne ""}


By "url exists", I assume you are asking does the URL variable have a value, and not if the URL is a real web page. You don't want to add networking tests in-template.
Back to top
View user's profile Send private message Visit poster's website
whatshakin
Smarty n00b


Joined: 24 Sep 2009
Posts: 3

PostPosted: Thu Sep 24, 2009 3:30 pm    Post subject: Lost Reply with quote

You can disregard what i posted there...i really have no idea what to do.

What i want to do is figure out how to get the current url and if it's home.php than display one thing. If it's anything different like: home.php?cat=278 than I would like something different displayed.

thanks
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Sep 24, 2009 4:47 pm    Post subject: Reply with quote

You could do:

Code:
{if !empty($smarty.get.cat)}
  {* there is a cat in the url, do something *}
  ...
{/if}
Back to top
View user's profile Send private message Visit poster's website
whatshakin
Smarty n00b


Joined: 24 Sep 2009
Posts: 3

PostPosted: Thu Sep 24, 2009 5:23 pm    Post subject: Solution Reply with quote

I found a plugin called currenturl. I installed it and used this code to display different content on the homepage than on the rest of the pages.

Works perfectly.

Code:
{currenturl var=currenturl}
  {if $currenturl eq 'http://www.grebitus.us/home.php'}
  <div class="right_image1">
    <img src="skin1/images/home_right1.jpg" alt="" />
  </div>
  <div class="right_image2">
    <img src="skin1/images/home_right2.jpg" alt="" />
  </div>

{elseif $currenturl eq 'http://www.grebitus.us/'}
  <div class="right_image1">
    <img src="skin1/images/home_right1.jpg" alt="" />
  </div>
  <div class="right_image2">
    <img src="skin1/images/home_right2.jpg" alt="" />
  </div>

{else}
      {include file="customer/menu_cart.tpl" }         
          {include file="modules/Bestsellers/menu_bestsellers.tpl" } 
{/if}
Back to top
View user's profile Send private message
jpiercemaine
Smarty Regular


Joined: 24 Sep 2009
Posts: 82

PostPosted: Fri Sep 25, 2009 7:11 pm    Post subject: Handle it in php Reply with quote

I know this is a smarty forum but why wouldn't you set a variable equal to the parameter passed. Then based on the variable you could set the content.

PHP:
Code:

$params=$_GET;
$category=$params["cat"];

$smarty->assign_by_ref("Category", $category);


Smarty:
Code:

{if $Category==1}
  show this
{elseif $Category==2}
  show that
{/if}



[/code]
Back to top
View user's profile Send private message
jonemere
Smarty n00b


Joined: 04 Jan 2010
Posts: 3

PostPosted: Wed Jan 06, 2010 9:33 am    Post subject: Reply with quote

Nice code man. It is very helpful to me. Nice information.

Thanks
_________________
2.5 hdd
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks 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