# Zoekresultaten aanpassen

**URL:** https://meta.discourse.org/t/modifying-search-results/258897
**Category:** Development
**Created:** [21 maart 2023 om 14:37 UTC](https://meta.discourse.org/t/modifying-search-results/258897 "2023-03-21T14:37:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [21 maart 2023 om 14:37 UTC](https://meta.discourse.org/t/modifying-search-results/258897/1 "2023-03-21T14:37:28Z")

</div>

I want to be able to tweak some of the styling in the search results (dropdown from the magnifying class in the top right). Now that seems to generate components on the fly (in `app/assets/javascripts/discourse/app/lib/search.js`) instead of using a template. I seem to be unable to do

```plaintext
      api.modifyClass("component:search-result-post", {
        didInsertElement() {
          this._super(...arguments);

        },
      });

```

or something similar.

How can I get a trigger/event and modify some of the generated HTML ?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [21 maart 2023 om 17:12 UTC](https://meta.discourse.org/t/modifying-search-results/258897/2 "2023-03-21T17:12:35Z")

</div>

Hi Richard,

Can you elaborate on what modifications you are looking for?

As starting point, I believe you would need to play around:

```js
api.reopenWidget(`search-result-post`, {
    html(attrs) {
        //
    }
})

```

Here for `post`, but you have also: `tag`, `category`, `group`, `user`, and `topic`.

> <https://github.com/discourse/discourse/blob/7f486cbc9b187976ee6dd21b5b0677ffe272f56d/app/assets/javascripts/discourse/app/widgets/search-menu-results.js#L93>

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [22 maart 2023 om 08:29 UTC](https://meta.discourse.org/t/modifying-search-results/258897/3 "2023-03-22T08:29:09Z")

</div>

Thank you for your help!!!

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [23 maart 2023 om 11:28 UTC](https://meta.discourse.org/t/modifying-search-results/258897/4 "2023-03-23T11:28:08Z")

</div>

Update: the HTML generation in that widget was pretty complex and it had a lot of external dependencies. I also didn’t want to copy all that code to our plugin, so I ended up doing this

```js
      api.reopenWidget(`search-result-topic`, {
        html(attrs) {
          const html = this._super(attrs);
          // modify html as we see fit
          return html;
        }
      });

```

Modifying the already generated HTML is probably not the most elegant way to do it, but it saved me from having to copy a large block of code from core to the plugin, making the plugin more robust against future core updates.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [23 maart 2023 om 11:38 UTC](https://meta.discourse.org/t/modifying-search-results/258897/5 "2023-03-23T11:38:17Z")

</div>

Yeah, I also noticed that when I did try on my side. I believe you don’t have much choice here.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [22 april 2023 om 11:39 UTC](https://meta.discourse.org/t/modifying-search-results/258897/6 "2023-04-22T11:39:14Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
