[Search] Inject id and class attr into individual result #3142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Give much more flexibility on the type of content and theming possibilities for each individual search result.
We could already manipulate the response received by the Search API:
The problem is that we couldn't inject the
id
andclass
attributes to each individual item rendered by the Search module.Now, depending on the status of each response, the status potentially reflecting a given website's logic and needs, we can inject an id and additional classes that can then be used for theming and manipulating.
Also, before each item was wrapped within a
<a>
tag. Because HTML prohibits having nested<a>
tags (which makes sense), we couldn't inject any link into the body of individual items (e.g. inject relevant links to open in a different browser tab, while keeping the result popup menu open).Now, if the result item has
result[fields.url]
, then keep the<a>
tag, because it makes sense: the whole result is assigned an URL.If
result[fields.url]
is absent, the result is wrapped within a<div>
tag, making it possible to inject one or even several links into the result's description, as may be required.This feature is backward-compatible, as the default behavior is unchanged.