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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:53:24+00:00 2026-05-30T18:53:24+00:00

I have a requirement to perform an indexed search across content which must include

  • 0

I have a requirement to perform an indexed search across content which must include a couple of tags in the result. The tags must be a random selection. The platform is Drupal 7.12

I have created a view that manages the results of a SOLR search through the search_api. The view returns the required content and seems to work as intended. I have included a couple of Global: custom text fields as placeholders for the tag entries.

I am now looking for a solution to manage the requirement to randomise the tag values. The randomisation is not the issue, the issue is how to include the random values into the view result.

My current approach is to write a views_pre_render hook to intercept the placeholders which appear as fields ([nothing] and [nothing_1]). The test code looks like the following

function MODULE_views_pre_render( &$view )
{
    $view_display = $view->display['default'];
    $display_option = $view_display->display_options;
    $fields = $display_option['fields'];
    foreach( $view->result as $result )
    {
        $fields['nothing']['alter']['text'] = sprintf("test %d", rand(1,9));
    }
}

I am currently not seeing any change in the placeholder when the view is rendered.

Any pointers to approach, alternate solutions etc would be gratefully received as this is consuming a lot of scarce time at the moment. Calling print_r( $view ) from within the hook dumps over 46M into a log file for a result set of 2 items.

  • 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-30T18:53:25+00:00Added an answer on May 30, 2026 at 6:53 pm

    There are two possible solutions for your task.

    First approach is do everything on the template level. Define a template for the view field you want to randomize. In advanced settings of your display go to Theme: Information. Make sure that the proper theme is selected and find the template suggestions for your field. They are listed starting from most general to the most specific and you can choose whatever suits you better.
    I guess the most specific template suggestion for your field would be something like this: views-view-field–[YOR VIEW NAME]–[YOUR DISPLAY NAME]–nothing.tpl.php. Create the file with that name in the theme templates directory and in this template you can render what ever you want.

    By default this template has only one line:

      print $output;
    

    you can change this to:

      print sprintf("test %d", rand(1,9));
    

    or to anything else, whatsoever 🙂

    Second approach is to go with Views PHP module. WIth this module you can add a custom PHP field in which you can do whatever you want. Even though the module hasn’t been released it seems to work quite well for the most of the tasks and most certainly for such a simple task as randomizing numbers it will work out for sure.

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

Sidebar

Related Questions

I have a requirement. Given say Test1,Test2, I have to perform a like operation.
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have the requirement to search several different tables in my SQL Server database.
My Application can perform 5 business functions. I now have a requirement to build
I have a requirement to perform HTTP authentication logic within a servlet application, rather
How to perform 256 Bit AES Encryption (Using Rijndael algorithm). Requirement: I have implemented
I have a requirement to build features that perform certain background tasks on a
I have a requirement to Perform the SHA1 hashing on the UTF-8 bytes of
I have a requirement in my application where we have to perform certain activities
I have modified a SharePoint visual studio workflow which works as per requirement on

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.