Skip to main content
Community Expert
December 19, 2016
Question

Mark pdf, word, excel files in search results

  • December 19, 2016
  • 2 replies
  • 865 views

Hi all,

I'm using RH11, Multiscreen HTML5 output in a merged structure, hosted on a webserver.

I couldn't see anything obvious, but is there any way to mark search results that aren't html files?

For example, if the search results include a pdf document, can I turn on something so that a little pdf icon appears next to the link?

Regards,

Amber

This topic has been closed for replies.

2 replies

JonathanSmith
Participant
January 4, 2017

Love it!

Willam van Weelden
Inspiring
December 31, 2016

Well, how much effort would you like to put into it?

The file search.js (template/scripts) has a function called writeResult that writes the search results to the pane. It generates the HTML of the search results and you can manipulate that any wat you want.

By adding a check for the resulting filename, you should be able to figure out the filetype and change the generated HTML accordingly. I haven't tried it though, but I expect it to work. It may be a pain to format though.

AmebrCommunity ExpertAuthor
Community Expert
January 3, 2017

Ah, so no built-in way. Thanks.

I figured out a way in CSS using :before and :after, although I'm still debating the pros and cons of this method.

I pasted relevant images into the screen layout directory, and to make sure the images appear in RH and get included in the build, I created fake html tags in the screen layout css (I suppose I could have used baggage file, too).

/* fake tags so the images appear in RH, which doesn't seem to know about content urls yet */

rh-word {

  background-image: url('word.png');

}

rh-pdf {

  background-image: url('PDF.gif');

}

Then I created a complex selector for the search results, to detect ".pdf" or ".doc" in the hyperlink. I had to use the developer console to figure out what the output code was doing:

/* find ".doc" or ".pdf" inside the href value and set an image before the a tag. Add a little padding so it's separate from the link text. */

.wSearchResultItem a[href*=".doc"]:before {

  content: url('word.png');

  padding-right: 5px;

}

.wSearchResultItem a[href*=".pdf"]:before {

  content: url('PDF.gif');

  padding-right: 5px;

}

I also had to change the div which displays the text to display: inline-block, otherwise the image was pushed into a separate paragraph. I had to set this on both .wSearchResultTitle and .wSearchResultTitleHover.

This is with RH11, Multiscreen HTML5 in a simple test project, targeting desktop output only. I haven't tried in my live merged output yet. I also haven't tried in Responsive HTML5, nor looking at phone or tablet output, so no idea if this would work in those environments.

Regards,

Amber

Willam van Weelden
Inspiring
January 3, 2017

That's a clever solution. Thanks for sharing! I can already see some uses for this