attj
September 6, 2022, 8:29am
1
I have the following import statement in my code (javascript side):
import Tag from "discourse/models/tag";
However, I can’t use it to retrieve a tag object by it’s name. My goal is to obtain the tag description, but I only have the name. I was expecting something similar to this:
const tagObj = Tag.find("tag_name");
const tagDesc = tagObj.description;
Does the Tag model have a similar function?
1 Like
keegan
(Keegan George)
September 13, 2022, 10:36pm
2
You can fetch tag data from the /tags.json
endpoint.
In this example I’m getting an email
tag’s description:
import { ajax } from "discourse/lib/ajax";
ajax(`/tags.json`).then(({ tags }) => {
const emailTag = tags.find((tag) => tag.name === "email");
const emailTagDesc = emailTag.description;
});
4 Likes
attj
September 17, 2022, 10:04am
3
Thanks! I guess I found a more efficient way to accomplish this:
this.store.find("tag-info", "email").then(data => {
const tag_desc = data.description
});
However, I don’t know if this.store.find
is faster than sending an ajax query to all tags and filtering. Maybe it’s doing the same thing.
2 Likes