Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3631900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:27:24+00:00 2026-05-19T00:27:24+00:00

As you will guess i’m new to php. Thanks for your help. I have

  • 0

As you will guess i’m new to php. Thanks for your help.
I have this piece of code in a header tpl:

<div class="menu">
            <ul>                                                                         
                <li class="selected"><a href="#">home</a></li>
                <li><a href="#">carta</a></li>
                <li><a href="#">delicias artesanas</a></li>
                <li><a href="#">contacto</a></li>
                <li><a href="#">d&oacute;nde estamos</a></li>
            </ul>
        </div>

which I’d like to call with PHP function include.
The thing is, I want to call this tpl, indicating which one of the li’s will have the “selected” class applied, how can I do that?
As I told you, easy peasy for anyone with basic PHP experience.
THANK YOU.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:27:25+00:00Added an answer on May 19, 2026 at 12:27 am

    You can base it off of a variable that is set in your calling (non-template) logic. For instance, in smarty you could do this in the PHP:

    // Determine which section user is in and pass to tpl
    $smarty->assign('location', 'home');
    

    Then in your template you can just check that variable:

    <li{if $location eq 'home'} class="selected"{/if}><a href="#">home</a></li>
    <li{if $location eq 'carta'} class="selected"{/if}><a href="#">carta</a></li>
    

    The keeps HTML out of your biz logic (PHP) and in your display logic (tpl).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess no one will have a definative answer to this but considered predictions
I have written some code in java that will guess a number based on
I guess there will be a very simple answer to this. But here goes.
How do I check if a URI exists with PHP? I guess it will
I guess this question will sound familiar, but I am yet another programmer baffled
My guess is that this question will fall under the category of duh, but,
I guess it is impossible, but I will ask it anyway. I have a
I'm pretty new to the Springframework (as you will guess) and ran into a
I've been staring myself blind on this problem I have and I guess this
I guess this will sound crazy, but I am reading from a file, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.