Menu class PHP script error

Discussion in 'Templates customization' started by lukeshields, Dec 29, 2009.

  1. lukeshields

    lukeshields Member

    Joined:
    Apr 12, 2005
    Messages:
    34
    I am editing the header.html file in the /templates folder - what I would like to do is check if the URL is either /signup.php or /member.php and then style the menu current state accordingly.

    Here is the script:

    PHP:
    <?php
    $path 
    $_SERVER['PHP_SELF'];
    $file basename($path".php"); // $file is set to "index"
    ?>
    <?php 
    if($file == 'member'){ echo 'current'; } ?>
    <?php 
    if($file == 'signup'){ echo 'current'; } ?>
    The first portion works fine but the IF statements do not, seems to be a Smarty error.

    Anyone know the correct syntax for aMember?
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    PHP:
    <?php
    $path 
    $_SERVER['PHP_SELF'];
    $file basename($path".php"); // $file is set to "index"
    echo $file//Check variable contents
    exit;
    ?>
    <?php 
    if($file == 'member.php'){ echo 'current'; } ?> //added .php
    <?php if($file == 'signup.php'){ echo 'current'; } ?> //added .php
    Firstly I would always suggest, if something fails to work is check what a variable ACTUALLY contains and have added the echo $file as a check.

    With your actual code you have joined the 'path' to '.php' to form 'member.php' or 'signup.php' so the if will always fail!
  3. aser

    aser Moderator

    Joined:
    Apr 25, 2007
    Messages:
    13
    Also please use:

    {php}
    //...
    {/php}

    within Smarty templates instead of

    <?php
    //...
    ?>
  4. lukeshields

    lukeshields Member

    Joined:
    Apr 12, 2005
    Messages:
    34
    Hi thehpmc, thanks, I already had checked the output and it contains either "member" or "signup" rather than member.php or signup.php.

    aser, thanks for the correct Smarty usage - I now have this which works correctly on a list menu item:

    PHP:
    {php
    $path $_SERVER['PHP_SELF']; 
    $file basename($path".php"); //$file is set to member or signup 
    {/php}

    <
    ul id="nav">
    <
    li><a href="domain.com/members/member.php" {php} if($file == 'member'){ echo 'class="current"'; } {/phptitle="My account page">Login &ampMy Account</a></li>
    <
    li><a href="domain.com/members/signup.php" {php} if($file == 'signup'){ echo 'class="current"'; } {/phptitle="Signup ">Signup</a></li>
    Hope it helps someone else...thanks for your help!

Share This Page