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.

EE 2.5 IF statement

May 23, 2012 5:52am

Subscribe [6]
  • #1 / May 23, 2012 5:52am

    Hi,

    I have a if statement ina channel tag:

    {exp:channel:entries channel ="channelname" limit="1" dynamic="no"}
    
                   {if title != ""}
    hi
    {/if}
    {/exp:channel:entries}

    And when i do run this code i will get the following error code:
    Parse error: syntax error, unexpected T_ENDIF in /var/www/vhosts/sitename.nl/httpdocs/system/expressionengine/libraries/Functions.php(680) : eval()‘d code on line 49

    And i don’t inderstand this one. The if statement is correct etc.

    I tried this with custom and default tags and all give me the same error.

    What is going wrong?

    Kind regards,

    Paul

  • #2 / May 23, 2012 12:46pm

    Rob Allen

    3114 posts

    “title” is a core variable so it’s always present with every entry, that’s what’s probably causing it to fall over.

    You shouldn’t need to use a conditional with it - you either have the {title} tag in your template or not have it?

  • #3 / May 24, 2012 3:00am

    Hi Rob,

    I have tried this with a custom entry tag and then the same thing happens.

  • #4 / May 24, 2012 3:20am

    This is the code i originally used:

    {exp:channel:entries channel ="channelname" limit="1" dynamic="no"}
       {if some_file_fiel == ""}
           tada no file
       {/if}
    {/exp:channel:entries}


    When i use this code in other template files it does work. On this page it doesn’t. And i don’t understand why. I should be able to do this on every template i want to.

  • #5 / May 24, 2012 10:52am

    Shane Eckert

    7174 posts

    Hello Bubblefish Interactive,

    Can you paste in the code for the template where it’s not working?

    It could be that you are running into Parse Order depending on what comes before and after. Is this a snippet or an embed?

    Thank you,

  • #6 / May 29, 2012 4:43am

    Hi Shane,

    Sorry for the late reaction. I had a long weekend off. Below you will find the entiere template. This is the index of a template group.

    {embed="_delen/_head"}
    {embed="_delen/_top_visual" visualpage="pagename"}
    {embed="_delen/_header"}
    
    <div class="content_vervolg_inner">
        {embed="_delen/_breadcrumbs"}
        
        <div class="linker_content_wrapper">
            <span class="dubbellijn"></span>
            <h1 class="header_title">pagename</h1>
            
           
            
            <span class="dubbellijn"></span>
            <h2 class="header_title pt_sans">Activiteiten</h2>
            {exp:channel:entries channel ="activiteiten_channel" limit="1"}
            <div class="nieuwsitem_overzicht">
             <div class="nieuwsafb_overzicht">
                 <a href="http://{homepage}templatename/channelname/{url_title}/P0">_                  {if some_file_field == ""}_       tada no file_   {/if}_                {exp:ce_img:pair src="{some_file_field}" max_width="171"}_{made}_{/exp:ce_img:pair}</a>
                </div>
                <div class="nieuwsitem_content_overzicht">
                 
                    <h2><a href="http://{homepage}templatename/channelname/{url_title}/P0">{title}</a></h2>
    <p>                {exp:strip_html}<br />
                        {exp:char_limit total="220"}{some_inleiding}{/exp:char_limit}<br />
                        {/exp:strip_html} <br />
                </div><br />
                <a href="http://{homepage}templatename/channelname/{url_title}/P0" class="leesmeernieuws_overzicht">Lees meer<span class="pijl"></span></a><br />
            </div><br />
            {/exp:channel:entries}<br />
            <a href="http://{homepage}templatename/channelname/P0/" class="meerover"> meer  items</a><br clear="all" ><br />
         <br />
          <br />
    </div></p>
    
    <p>    <br />
        {embed="_delen/_sidebalk_rechts"}<br />
    </div></p>
    
    
    
    <p><br />
    {embed="_delen/_footer"}

  • #7 / May 30, 2012 4:31pm

    Shane Eckert

    7174 posts

    Hello Bubblefish,

    What if you use just this in a template?

    {exp:channel:entries channel ="channelname" limit="1" dynamic="no"}
       {if some_file_fiel == ""}
           tada no file
       {/if}
    {/exp:channel:entries}

    Does your logic work?

    Thanks,

  • #8 / Jun 01, 2012 3:44am

    Hi Shane,

    The code does work on other templates. That is the stange part.

    But there is more…

    It even works with the same channel and the same entry..

    The only difference on the page where it does work, is that the channel uses 5 entries and has pagination…

    And thats the point where i did lost it. The same code, on another template works only on this template it doesn’t..

  • #9 / Jun 01, 2012 4:20am

    jelle

    104 posts

    did you try deleting the template, and recreating it?

  • #10 / Jun 01, 2012 4:23am

    Hi Jelle,

    Yes we did, this made no difference..

  • #11 / Jun 01, 2012 5:46am

    Thanks to some help on Twitter:

    I should use:

    {if '{my_field_name}’ == “”}
    tada
    {/if}

    I tried and it works like a charm.

  • #12 / Jun 01, 2012 12:38pm

    OrganizedFellow

    435 posts

    I’m glad it was resolved.
    If I should ever encounter this problem, I can find this thread as the solution!

  • #13 / Jun 01, 2012 2:16pm

    OwanH

    87 posts

    Hi all, I know that this thread has been resolved but I still thought I would give an explanation as to why this problem would have been encountered so anyone reading this thread would understand the “why” and not just the “how to fix it”. Basically, if you attempt to do something such as:

    {if some_custom_field == ""}
    ...

    or even just

    {if some_custom_field}
    ...

    and some_custom_field is a text/textarea/wysiwyg field that contains any quotes or certain special characters you will more than likely get a PHP error. I myself ran in to this problem numerous times before realising what the cause was.

    Also I can confirm as well that, as was pointed out, putting

    {if '{some_custom_field}’ == “”}

    can get around the issue.

  • #14 / Jun 05, 2012 3:18pm

    Shane Eckert

    7174 posts

    Hey All,

    Nice work here!

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases