If page is... A, else, B

Discussion in 'Templates customization' started by sboben, May 21, 2008.

  1. sboben

    sboben New Member

    Joined:
    Oct 5, 2006
    Messages:
    48
    Does Smarty have a tag which allows it to know which page it's on? Something like... if_current_page ?

    I have a sidebar on my member pages that I call in through an include file. I want the current page item to be styled differently than the other pages in the menu but I can't do that unless the list item has a "current-page" class on it. If Smarty had a conditional tag, I could insert the class on the current item and control the style via the CSS.

    My menu looks like this:

    Code:
    <ul>
      <li><a href="{$config.root_url}/member.php">Download Account</a>
        <ul>
          <li><a href="{$config.root_url}/profile.php">Change Password</a></li>
          <li><a href="{$config.root_url}/aff_member.php">Affiliate Summary</a></li>
          <li><a href="{$config.root_url}/aff.php?action=links">Banners &amp; Links</a></li>
          <li><a href="{$config.root_url}/aff.php?action=stats">Archived Statistics</a></li>
          <li><a href="{$config.root_url}/aff.php?action=payout_info">Payment Settings</a></li>
        </ul>
      </li>
      <li><a href="/blog/wp-admin/profile.php">Blog Account</a></li>
    </ul>
    
  2. tomfra

    tomfra Member

    Joined:
    Dec 21, 2006
    Messages:
    199
    PHP:
    <ul>
      <
    li><a href="{$config.root_url}/member.php"{if $smarty.server.REQUEST_URI == "/amember/member.php"} class="current-page"{/if}>Download Account</a>
        <
    ul>
          <
    li><a href="{$config.root_url}/profile.php"{if $smarty.server.REQUEST_URI == "/amember/profile.php"} class="current-page"{/if}>Change Password</a></li>
          <
    li><a href="{$config.root_url}/aff_member.php"{if $smarty.server.REQUEST_URI == "/amember/aff_member.php"} class="current-page"{/if}>Affiliate Summary</a></li>
          <
    li><a href="{$config.root_url}/aff.php?action=links"{if $smarty.server.REQUEST_URI == "/amember/aff.php?action=links"} class="current-page"{/if}>Banners &ampLinks</a></li>
          <
    li><a href="{$config.root_url}/aff.php?action=stats"{if $smarty.server.REQUEST_URI == "/amember/aff.php?action=stats"} class="current-page"{/if}>Archived Statistics</a></li>
          <
    li><a href="{$config.root_url}/aff.php?action=payout_info"{if $smarty.server.REQUEST_URI == "/amember/aff.php?action=payout_info.php"} class="current-page"{/if}>Payment Settings</a></li>
        </
    ul>
      </
    li>
      <
    li><a href="/blog/wp-admin/profile.php"{if $smarty.server.REQUEST_URI == "/blog/wp-admin/profile.php"} class="current-page"{/if}>Blog Account</a></li>
    </
    ul>
    Don't forget to change the /amember dir name if you have aMember installed elsewhere. It's probably possible to write some better code for the same purpose but this should work.

    Tomas

Share This Page