Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Simple IF statement Help Rate Topic   - - - - -

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 01:55 PM #1

For my index page I would like to include a file other than main.tpl so I need to write a simple if statement that checks for the index page, if true loads new.tpl, if false loads main.tpl.

I believe it would look something like this but I don't know how to check for the index page....

{if [I]page=index[/I]}
		{include file="main.tpl"}
    {else}
    	{include file="new.tpl"}
    
    {/if}

Can anyone help me with this statement please? Thanks!

 
  • joe
  • Senior Member
  • Members
  • Join Date: 06-Jan 09
  • 824 posts

Posted 30 July 2009 - 02:21 PM #2

A simple if?
PM me for custom project

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 03:17 PM #3

Is that not simple?

Figured there would be some kind of variable for current page or something I don't know?

 
  • Triplets
  • Senior Member
  • Members
  • Join Date: 23-Sep 08
  • 1179 posts

Posted 30 July 2009 - 03:31 PM #4

http://www.smarty.ne...function.if.php

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 03:40 PM #5

I don't think that is what I'm looking for. I'm looking for a way to check the current page being viewed. The bold values is what I think i need. If they even exist...

{if [B]$current_page[/B]==[B]index.php[/B]}


 
  • Triplets
  • Senior Member
  • Members
  • Join Date: 23-Sep 08
  • 1179 posts

Posted 30 July 2009 - 03:47 PM #6

I believe the smarty engine requires single quotes around strings in an if statement.

http://www.smarty.ne....unction.if.php

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 04:10 PM #7

ok so it would look something like this

{if $current_page == 'index.php'}
{include file="new.tpl"}
{else}
{include file="main.tpl"}
{/if}

But what I'm really trying to figure out is if there is some kind of built in variable like $current_page. I just made that up for demostration purposes. Or maybe that is something I have to define myself?

 
  • Triplets
  • Senior Member
  • Members
  • Join Date: 23-Sep 08
  • 1179 posts

Posted 30 July 2009 - 04:21 PM #8

I beleive it is $current_url

Turn on the Debugging Console and then you can see all the variable values when a page loads.

David

 
  • baballuci
  • Senior Member
  • Members
  • Join Date: 02-Mar 06
  • 969 posts

Posted 30 July 2009 - 04:57 PM #9


{if $config.current_url == 'index.php'}


Charlie

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 05:59 PM #10

Yeah you are right its $current_url.

I tried this but it's not working.

{if $current_url == 'index.php'}
{include file="new.tpl"}
{else}
{include file="main.tpl"}
{/if}

The else statement is always executed. I tried inserting just the variable {$current_url} into the page to see if it would output something but It didn't. Can someone maybe steer me in the right direction? Thanks.

 
  • msfarrel
  • Junior Member
  • Members
  • Join Date: 30-Jul 09
  • 20 posts

Posted 30 July 2009 - 06:42 PM #11

Thanks baballuci! I didn't see your post earlier. That works.

 
  • snorocket
  • Forum Janitor
  • Members
  • Join Date: 15-Mar 06
  • 2519 posts

Posted 11 August 2009 - 07:38 PM #12

you can also use:
{if $mode == 'index'}
{include file="main-1.tpl"}
{elseif $mode == 'products'}
{include file="main-2.tpl"}
{elseif $mode == 'categories'}
{include file="main-3.tpl"}
{elseif $mode == 'cart'}
{include file="main-4.tpl"}
{elseif $mode == 'checkout'}
{include file="main-5.tpl"}
{else}
{include file="main-6.tpl"}
{/if}
ect...
SNOROCKET.COM, Now Accepting PRE-ORDERS:
Customer Service (Helpdesk) Addon for CS-Cart v4.3.1
Quote and Invoicing Addon for CS-Cart v4.3.1

 
  • indymart
  • BANNED FOR SPAM
  • Members
  • Join Date: 14-Feb 06
  • 17 posts

Posted 12 August 2009 - 01:16 AM #13

What about mode search controler search.php?
Also: if home page in 2.0.6.
Thank you.

QUOTE=snorocket;56888]you can also use:
{if $mode == 'index'}
{include file="main-1.tpl"}
{elseif $mode == 'products'}
{include file="main-2.tpl"}
{elseif $mode == 'categories'}
{include file="main-3.tpl"}
{elseif $mode == 'cart'}
{include file="main-4.tpl"}
{elseif $mode == 'checkout'}
{include file="main-5.tpl"}
{else}
{include file="main-6.tpl"}
{/if}
ect...[/QUOTE]