Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

if-statement for variables, strings etc.


Reply


4 Posts   3547 Views

Avatar
joelg

Community Member, 129 Posts

7 October 2008 at 10:51pm

Hi Everyone

I have a smaller problem that I need some help with. And it should be really simple.

I want to create an if statement for variables in my classes/templates, just like I do with menus in the template, i.e.

<% if Menu(2) %>
   <div id="mySecondMenu">
      <% control Menu(2) %>
      ...
       <% end_control %>
</div>
<% end_if %>

So what I basically would do is this:

<% if $myImage %>
   <img src="$myImage"/>
<% end_if %>

Does it make sense?

I'll try to explain. Let's say for instance that I've created an image in a template (both in the class file and template), but the user doesn't fill it out in the backend. Now of course the image doesn't show up in front, because there is no, instead the browser is showing me a questionmark, and that looks pretty silly.

Can anyone help, thanks.

Joel

Avatar
Hamish

Community Member, 712 Posts

7 October 2008 at 11:15pm

Ah,

Remove the dollar sign. Your template should look like:

<% if myImage %>
<img src="$myImage"/>
<% end_if %>

Should work fine :)

Avatar
joelg

Community Member, 129 Posts

8 October 2008 at 12:01am

Great, works! Thanx...

Avatar
joelg

Community Member, 129 Posts

8 October 2008 at 12:15am

Ok, one more question though.

I've tried to make two checks with the && sign, and that works too.

Now, is there a way to write "or", something like this:

<% if MyFirstVariable or MySecondVaribale %> //Where either the first or second variable is true?

Thanks again...