# Topic ID as a variable?

**URL:** <https://meta.discourse.org/t/topic-id-as-a-variable/374168>\
**Category:** Development\
**Created:** [July 14, 2025, 6:48pm UTC](https://meta.discourse.org/t/topic-id-as-a-variable/374168 "2025-07-14T18:48:32Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [September 27, 2025, 11:41am UTC](https://meta.discourse.org/t/topic-id-as-a-variable/374168/24 "2025-09-27T11:41:46Z")

</div>

@tknospdr @pfaffman I cobbled together a quick component that allows you to input the topic id and jump to it.

Create a new component, and add this to the JS tab under the Edit CSS/HTML button\[1\]:

```gjs
import { apiInitializer } from "discourse/lib/api";
import Component from '@glimmer/component';
import { action } from "@ember/object";
import Form from "discourse/components/form";
import DiscourseURL from "discourse/lib/url";

export default apiInitializer((api) => {
    api.renderBeforeWrapperOutlet("full-page-search-filters", 
        class GoToTopic extends Component {
            @action
            handleSubmit(data) {
                DiscourseURL.routeTo(`/t/${data.id}`);
            }
            
            <template>
                <div class="topic-id-go-to" style="margin-top: 1em;">
                    <Form @onSubmit={{this.handleSubmit}} as |form|>
                    
                      <form.Field @name="id" @title="Topic id" as |field|>
                        <field.Input @type="number" @validation="required" />
                      </form.Field>
                    
                      <form.Submit />
                    </Form>
                </div>
            </template>
        }
    );
});

```

This adds an input to the Search page:

 ![image](https://global.discourse-cdn.com/meta/original/4X/e/9/9/e9915704639e3338e6942515239d20308ae4886b.png)  
The Submit button is to go to the topic\[2\]; it does not affect search results.

Hope this helps!

* * *

1. My first time using FormKit, it’s really cool! 

2. I couldn’t change the button text, as that would require locales… which would need a whole TC repo, which might be overkill 🤷.

---

_[View the full topic](https://meta.discourse.org/t/topic-id-as-a-variable/374168)._
