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.

PHP if statement with tags

March 10, 2011 12:57pm

Subscribe [4]
  • #1 / Mar 10, 2011 12:57pm

    cpaws

    25 posts

    I’m not quite sure why this isn’t working.

    I’m trying to evaluate two variables, both of which get their values from expressionengine tags. I’m inside of a channel:entries tag, and this is the code:

    <?php 
    
    $current_url = "{homepage}/{segment_1}/{segment_2}";
    $details = "{comment_url_title_auto_path}";
    
    if ($current_url == $campaign_details){
            echo "true";
        }
    
    ?>

    I can’t get it to say true. If I echo out $current_url and $details, they show the proper values. Any ideas?

  • #2 / Mar 11, 2011 4:19am

    John Henry Donovan

    12339 posts

    cpaws,

    Check your PHP parsing method on the template. Try changing it to Input in your template preferences. Echo out your $details variable and make sure there is no extra beginning or trailing slash. Alos try moving the Scurrent_url outside the channel:entries tag

    Can I ask what you are trying to achieve? Maybe you don’t need PHP at all.

  • #3 / Mar 11, 2011 10:37am

    cpaws

    25 posts

    PHP is already on Input. There are no extra slashes. $current_url has the same value anywhere I put it. Both variables echo out the correct value. It will show me both values being the same and it still won’t say true.

    I’m pulling in custom fields with tags. Some articles already include this custom field, in which case I want to do something slightly different with it in the list. I could achieve this using two loops, but that seems like a waste of code when there’s no reason something this simple shouldn’t work.

  • #4 / Mar 11, 2011 4:17pm

    Sue Crocker

    26054 posts

    Hi, cpaws. If you’re inside of a exp:channel:entries loop, you need to use PHP in output mode. So you need input for some of this, and output for the rest. You could do some sort of passing of your PHP variable to an embed. That might work.

  • #5 / Mar 21, 2011 11:34am

    rockbeatspaper

    9 posts

    cpaws, looks like your variable name are not matching…. $details on line 2 and $campaign_details on line 3.  Could that be the culprit, or are we just not seeing other code that you have in your template that uses the two variables?

  • #6 / Mar 22, 2011 5:04am

    John Henry Donovan

    12339 posts

    Thanks John, good catch. Maybe its as simple as that, cpaws?

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

ExpressionEngine News!

#eecms, #events, #releases