{if} statement question

Discussion in 'PHP' started by bschneider5, Jul 26, 2006.

  1. #1
    I'm setting up an articlescript based site, and need to add code to differentiate the home page from all the others. Can someone please help me out with some code to add? I figured it would be something like this but it doesnt work.

    {if $page eq '$smarty.const.DOC_ROOT'}test text{/if}
    Code (markup):
     
    bschneider5, Jul 26, 2006 IP
  2. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #2
    the format of if statement should be like this

    if(statement){
    statement
    }

    I am not sure with this but you can try it...

    
    if($HTTP_SERVER_VARS['DOC_ROOT']=="index.php"){
    echo "home";
    }else{
    echo "other files";
    }
    
    Code (markup):
    But for sure you can play on it.
     
    PinoyIto, Jul 26, 2006 IP
  3. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #3
    So where would I stick my text, etc?
     
    bschneider5, Jul 26, 2006 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is in a Smarty template, right?

    I don't know Smarty, but I do know that it's not the same as normal PHP.

    What if you just tried:
    {if $page eq $smarty.const.DOC_ROOT}test text{/if}

    That is, without the single quotes?
     
    TwistMyArm, Jul 26, 2006 IP
  5. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Nope, I just tried it and nothing.
     
    bschneider5, Jul 27, 2006 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OK: so just to be sure, you are doing this in a Smarty template, right? If it's just normal PHP, then it's going to be something totally different...
     
    TwistMyArm, Jul 27, 2006 IP
  7. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #7
    Right. It is a smarty type deal. ere is some {if} code that is already present on the file.
    {if $page eq 'article'}{$article[0]}
                    {elseif $page eq 'articles'}{$title}
                    {elseif $page eq 'last'}Last Articles
                    {elseif $page eq 'searchresult'}{$title}
                    {/if}
    Code (markup):
     
    bschneider5, Jul 27, 2006 IP
  8. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well, I guess the first thing to do is to dump the two variables on screen, just to see what value Smarty thinks they are...

    Just before your if, try something like:
    
    page value is: {$page}<br>
    smarty.const.DOC_ROOT value is: {$smarty.const.DOC_ROOT}<br>
    
    Code (markup):
    So at least now you can visually confirm that they are or are not the same...

    Does that make sense?
     
    TwistMyArm, Jul 27, 2006 IP
  9. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #9
    OK, Here is the code exactly as I put it in the file:
    page value is: {$page}<br>
    smarty.const.DOC_ROOT value is: {$smarty.const.DOC_ROOT}<br>
                    {if $page eq $smarty.const.DOC_ROOT}test text{/if}
                    {if $page eq 'article'}{$article[0]}
                    {elseif $page eq 'articles'}{$title}
                    {elseif $page eq 'last'}Last Articles
                    {elseif $page eq 'searchresult'}{$title}
                    {/if}
    Code (markup):
    This is what showed on every page, not just the main:

     				  				
    page value is: last
    smarty.const.DOC_ROOT value is:
    Last Articles
    Code (markup):
     
    bschneider5, Jul 27, 2006 IP
  10. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #10
    OK, I think I found a way around it. By default, the home page is the "last articles" so this is what I used and seems to work:
    {if $page eq last}test text{/if}
    Code (markup):
     
    bschneider5, Jul 27, 2006 IP
  11. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #11
    If that works, then congrats. The actual problem, though, is that $smarty.const.DOC_ROOT is not being initialised at all. Unfortunately, I don't know Smarty enough to know why, but that seems to be the problem, anyway.
     
    TwistMyArm, Jul 27, 2006 IP