View previous topic :: View next topic |
Author |
Message |
enginemike Smarty Regular
Joined: 28 Feb 2006 Posts: 57
|
Posted: Sat Sep 08, 2018 3:14 am Post subject: Using if else statement |
|
|
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 |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sat Sep 08, 2018 5:25 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Sep 08, 2018 1:18 pm Post subject: |
|
|
Empty elseif() condition evaluates to if(false)… which will never match. |
|
Back to top |
|
enginemike Smarty Regular
Joined: 28 Feb 2006 Posts: 57
|
Posted: Sat Sep 08, 2018 5:34 pm Post subject: Using if else statement |
|
|
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 |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sun Sep 09, 2018 1:34 am Post subject: |
|
|
What is it you are trying to do ? |
|
Back to top |
|
enginemike Smarty Regular
Joined: 28 Feb 2006 Posts: 57
|
Posted: Sun Sep 09, 2018 4:09 am Post subject: If/Else |
|
|
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 |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sun Sep 09, 2018 5:11 am Post subject: |
|
|
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 |
|
wajidafridi48 Smarty n00b
Joined: 18 Sep 2018 Posts: 1
|
Posted: Tue Sep 18, 2018 7:57 am Post subject: if else within tag |
|
|
<li <?php echo isset($_REQUEST['kpi'])? 'active' : '' ;?> >
</li>
How to implement it in smarty tpl file ? |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
|
Back to top |
|
|