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 8014569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:58:35+00:00 2026-06-04T19:58:35+00:00

I want in my template.php (drupal theme) something like this: $search_button =’search-button.png’; if($(‘#page-wrapper’).hasClass(‘blue-colour’)) {

  • 0

I want in my template.php (drupal theme) something like this:

$search_button ='search-button.png';
if($('#page-wrapper').hasClass('blue-colour')) {
    $search_button ='search-button-blue.png';
}
else if ($('#page-wrapper').hasClass('green-colour')) {
    $search_button ='search-button-green.png';
}
$form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/'.$search_button);

Which doesn’t work because it is jQuery. The problem is the syntax on this bit:

if($(‘#page-wrapper’).hasClass(‘blue-colour’))

How can I do the same thing without using javascript or jQuery and only php and/or some Drupal function?

I want to replace the icon for a search box based on a class set on a HTML element:

<div id="page-wrapper" class="blue-colour">

In this case it would check that the class is ‘blue-colour’ and would set the correct blue icon on the variable ($search_button).

  • 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-06-04T19:58:36+00:00Added an answer on June 4, 2026 at 7:58 pm

    This doesn’t answer your question directly, but you can solve this very nicely using just css:

    1. Don’t use an image for your button, but a text and do something like text-indent: -9999em;
    2. Set the background image of the button to the image you want like (simple example):
    .blue-colour .button {
       background: url(search-button-blue.png);
    }
    .green-colour .button {
       background: url(search-button-green.png);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to link a template php page (header.php) to a custom php page
I want to have a template class that looks something like what I have
I want to do something like template <typename T> void foo(const T& t) {
I want to add a custom search option on my drupal theme in a
Creating my WordPress author.php template page and ran into a little roadblock. I want
I would like to display a Drupal view without the page template that normally
I am creating a custom control. I want the template for this control to
I want to render same template on one page which should display the value
i want to code something in my post template. So, is there any way
I'm trying to make a custom theme for a drupal blog, and I want

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.