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

Using if else statement

 
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 -> General
View previous topic :: View next topic  
Author Message
enginemike
Smarty Regular


Joined: 28 Feb 2006
Posts: 57

PostPosted: Sat Sep 08, 2018 3:14 am    Post subject: Using if else statement Reply with quote

Hello
I am trying tio use the if else statement to select a view. The problem is that I would like to have a unique display for the mobile view. I have tried all kinds of variations but nothing seems to work. Maybe what I want cannot be done.

The code is

{if $page_type == 'index'}
<button type='button' class='basic_inactive menu' disabled>Home</button>

{elseif}
{literal}
function updateSizes()
{
//alert('xxxx');
var uniwin = {
width: window.innerWidth || document.documentElement.clientWidth
|| document.body.offsetWidth,
height: window.innerHeight || document.documentElement.clientHeight
|| document.body.offsetHeight
}
//alert(uniwin.width);

if (uniwin.width == 400)
{
alert('browser width equals 400px');
}

}

<button type='button' hidden>Home</button>


{else}
<button type='button' class='basic menu' onclick='pageSelect(0)'>Home</button>
{/if}

The if and else conditions work but the elseif condition does not work. Now the code is not complete I am just trying to see if I can get anything that indicates I am on the right track. Right now I just get a blank screen.

What I am trying to do is have the button not appear if the browser is less than 400px wide.

Any information would be greatly appreciated

Thank you
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sat Sep 08, 2018 5:25 am    Post subject: Reply with quote

the first {elseif} you have shown does not have a condition set to it.

if (something ?) then do the second bit of your code.

The last ELSE is OK - as that part will be displayed if the first two parts are not met.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Sep 08, 2018 1:18 pm    Post subject: Reply with quote

Empty elseif() condition evaluates to if(false)… which will never match.
Back to top
View user's profile Send private message
enginemike
Smarty Regular


Joined: 28 Feb 2006
Posts: 57

PostPosted: Sat Sep 08, 2018 5:34 pm    Post subject: Using if else statement Reply with quote

Thanks. I've come to the conclusion that what I want to do is not going to work using this approach.

I think I may be able to accomplish my goal using CSS. Experimenting.

Thanks for your comments.
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sun Sep 09, 2018 1:34 am    Post subject: Reply with quote

What is it you are trying to do ?
Back to top
View user's profile Send private message
enginemike
Smarty Regular


Joined: 28 Feb 2006
Posts: 57

PostPosted: Sun Sep 09, 2018 4:09 am    Post subject: If/Else Reply with quote

I have a web site with four pages. There is a button to navigate to each page. In the desktop/tablet mode all 4 buttons are visible (although the button for the current page is inactive).

In the mobile mode I decided to not show the button for the current page. I am doing this both to save space and it just seems like a neat hack.

Originally I was thinking to do it thru Smarty but after some effort decided that it was not possible (at least for me).

I then thought that I could do it using CSS3. With enough torture I was making some progress, but then finally I decided to use Javascipt. The Javascript approach is going very well and I have an operational version working; I still need to finish up with appearances using CSS.

I'm kind of like a dog gnawing on a bone long after it is used up; a character flaw.

I do thank all for the comments as they got me out of my ditch and moving again.
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sun Sep 09, 2018 5:11 am    Post subject: Reply with quote

Its easy in your Smarty.

1) in your main page put {assign var="page" value="1"} or 2, 3 4 etc...

2) in your navigation file you can put:

{if ( $page >1 )}
Include navigation to page 1.
{/if}
{if ( $page <2 or $page >2 )}
Include navigation to page 2.
{/if}
{if ( $page <3 or $page >3 )}
Include navigation to page 3.
{/if}
{if ( $page <4 )}
Include navigation to page 4.
{/if}

In the above code - it will HIDE the appropriate navigation to the current page. it will only show the navigation to the OTHER pages.

Im sure that other folk may advise a better way, but the above will work.
Back to top
View user's profile Send private message
wajidafridi48
Smarty n00b


Joined: 18 Sep 2018
Posts: 1

PostPosted: Tue Sep 18, 2018 7:57 am    Post subject: if else within tag Reply with quote

<li <?php echo isset($_REQUEST['kpi'])? 'active' : '' ;?> >
</li>

How to implement it in smarty tpl file ?
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Wed Sep 19, 2018 9:34 pm    Post subject: Reply with quote

<li{if $smarty.request.kpi} active{/if}>

See:
https://www.smarty.net/docs/en/language.variables.smarty.tpl#language.variables.smarty.request
Back to top
View user's profile Send private message
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 -> 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