ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Simple If Statements with Customer Globals?

December 01, 2010 6:57pm

Subscribe [8]
  • #1 / Dec 01, 2010 6:57pm

    rjfranco

    3 posts

    I haven’t been able to get simple {if} statements to work in the template for my index, using a custom global variable.

    I have setup {sitenotice}, and then in my template I have:

    {if sitenotice != ''}
    <h4>{sitenotice}</h4>
    <p>{/if}

    I’ve also tried

    {if sitenotice}
    <h4>{sitenotice}</h4>
    <p>{/if}

    But neither of these generate the contents of site notice.

    Is there some place I need to enable this option?

  • #2 / Dec 02, 2010 3:43pm

    Ingmar

    29245 posts

    No need to enable anything.

    {if foo != ""}
    <h4>{foo}</h4>
    <p>{/if}

    should definitely work.

  • #3 / Dec 02, 2010 9:45pm

    raraya

    1 posts

    I switched my single quotes to double quotes (though, I doubt that’d make a difference), but to no avail.

    http://twitpic.com/3cc8vq

    The picture shows exactly what’s going on .. I don’t have anything complicated in the template, as far as I can tell it should be working.

  • #4 / Dec 02, 2010 9:47pm

    rjfranco

    3 posts

    I switched my single quotes to double quotes (though, I doubt that’d make a difference), but to no avail.

    http://twitpic.com/3cc8vq

    The picture shows exactly what’s going on .. I don’t have anything complicated in the template, as far as I can tell it should be working.

  • #5 / Dec 03, 2010 9:38am

    Ingmar

    29245 posts

    Do you’ve got a link to the site? I suppose you have made sure to use “straight” quotes instead of curly “typographical” ones?

  • #6 / Dec 09, 2010 1:24pm

    rjfranco

    3 posts

    Yes, you can view the site via:

    http://soccerink.com/index.php

    (P.S. I tried to post this before and I wasn’t allowed to, I get a “Forbidden” error, I also can’t seem to view my own profile?)

    If you look at the source, you can see that the {if} has been removed, so I’m assuming that means that the engine is interpreting the template, just for some reason thinks the variable is empty even though it’s not.

    Thanks
    Ramiro Jr. Franco

  • #7 / Dec 10, 2010 4:45am

    John Henry Donovan

    12339 posts

    rjfranco,

    You can’t use a conditional with a global variable like this

    You can use it like this testing the condition of something else no problem but not a condition of itself

    {if foo != ""}
    <h4>{sitenotice}</h4>
    <p>{/if}

    Easiest solution here would be to change your global variable content to

    <h4>Free shipping on orders over $50</h4>

    Then you don’t need any conditional in your template. Just add {sitenotice}. If it has content it will show and if not it won’t

  • #8 / Dec 17, 2010 3:13pm

    rjfranco

    3 posts

    Well, I really think I’m going about this the wrong way. What would you consider best practice for creating a segment .. or blog, or variable or something that my customer can update, or clear, without knowing any html, and publishing it on the site? and if it’s clear, the segment would disappear from the site.

    Actually, some best practice methods documentation in general would be really nice, I’m really unsure of how to use EE 1.7 to best utilize it with something like CartThrob.

    Thank You
    Ramiro Jr. Franco

  • #9 / Dec 18, 2010 5:28pm

    Greg Salt

    3988 posts

    Hi rjfranco,

    I can’t offer any specific advice about integration with CartThrob but can you explain exactly what it is that you are trying to do? Is this information related to specific weblog (product) entries or general notices?

    Cheers

    Greg

  • #10 / Dec 22, 2010 8:33am

    GlobalGraphics

    36 posts

    Hi there guys,

    I am also trying to do the same thing like so:

    {if address_1 != ''}<address>{/if}
    {if address_1 != ''}{address_1}
    {/if}
    {if address_2 != ''}{address_2}
    {/if}
    {if address_3 != ''}{address_3}
    {/if}
    {if address_4 != ''}{address_4}
    {/if}
    {if address_5 != ''}{address_5}{/if}
    {if address_1 != ''}</address>{/if}

    Its pretty obvious what I want to do. I don’t want my customer to have to know any html. With your way if the variable is empty the <h4> tags still exist in the code.

    Cheers.

  • #11 / Dec 22, 2010 5:46pm

    Ingmar

    29245 posts

    I am not following. Regardless of whether you have <h4> in your snippet / variable or show it conditionally, it won’t be shown if the variable is empty. That said, were you just chiming on or do you have issues of your own?

  • #12 / Dec 23, 2010 5:49am

    GlobalGraphics

    36 posts

    I do have an issue of my own.

    I have created several global variables for a postal address.

    {address_1}
    {address_2}
    {address_3}
    {address_4}
    {address_5}

    I would like these variables not to contain any html as my customer doesn’t know any. I also want these variables to be optional hence wrapping each in an {if}.

    {if address_1 != ''}<address>{/if}
    {if address_1 != ''}{address_1}
    {/if}
    {if address_2 != ''}{address_2}
    {/if}
    {if address_3 != ''}{address_3}
    {/if}
    {if address_4 != ''}{address_4}
    {/if}
    {if address_5 != ''}{address_5}{/if}
    {if address_1 != ''}</address>{/if}

    This however is not working at all. Is there a better way to do what I am trying to achieve?

  • #13 / Dec 27, 2010 11:09am

    Sue Crocker

    26054 posts

    What’s it doing instead?

  • #14 / Jan 20, 2011 10:19pm

    Eric Snyder

    202 posts

    I am having the same issue. What it is doing instead is not outputting the value of the global variable. If I place the same global variable alone in the template it outputs. If it is wrapped in an if statement it does not.

  • #15 / Jan 20, 2011 10:48pm

    Eric Snyder

    202 posts

    This works if it is a snippet:

    {if phone_800_number}
    {phone_800_number}
    {/if}

    But not if it is a global variable.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases