בעיות עם renderInOutlet

I must be doing something very stupid, but I’m incapable of seeing it. I’m hoping that posting here will make me see it so I can delete this before anyone else knows how stupid I am.

“HELLO WORLD” should be rendering on the home page. I see “THIS IS THE HOMEPAGE” in the console. I know it’s firing. But it’s not there.

Then I tried adding “Extra item” because I didn’t have any other ideas. It’s not rendering either.

I did get errors before I renamed the file to .gjs, so that’s further evidence that it’s paying attention to the file and it’s making something happen.

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("1.8.0", (api) => {
  // see if we're on the home page
  api.onPageChange(() => {
    const router = api.container.lookup("service:router");
    const url = router?.currentURL;
    const isHomePage = url === "/";
    api.renderInOutlet("top-notices", <template>Extra item</template>);
    if (isHomePage) {
      console.log("THIS IS THE HOMEPAGE");
      api.renderInOutlet("after-header", <template>HELLO WORLD</template>);
    }
  });
});

Is it possible the outlets aren’t yet rendered so there is no outlet to attach to?

onPageChange is fired on a route change …

זה נראה כמו סוג הדברים הטיפשיים שאני מדבר עליהם!!

אני רוצה שזה יקרה רק בעמוד הבית.

אבל כן! אם אני מעביר אחד מאלה של ה-render מחוץ ל-onPageChange, זה רנדר.

אז איך אני עושה את זה לקרות רק אם ה-URL הוא /?

אולי אני אעשה באמת רכיב ואוסיף קריאה ל-shouldRender()?

אתה צריך להוסיף את שירות הנתב (בתוך רכיב) ולהגדיר מאתחל גיטר.

2 לייקים

תודה מיליון תודות! אני יודע mostly מהכל מילים האלה معنی!

לייק 1

Well I’m hoping this helps! Please confirm once it’s all fired up!

לייק 1

Oh, baby! I really did know what a service was! I really did know what a getter was! Now my text is rendering on the home page and not on another page (and presumably all of the rest of them!).

4 לייקים

נושא זה נסגר באופן אוטומטי 30 ימים לאחר התגובה האחרונה. תגובות חדשות כבר לא מותרות.