System Information
- Strapi Version: 3.6.8
In the backend of your plugin you can use the global strapi.contentTypes
variable to fetch all Single and Collection types.
Thanks @boaz , but I console log strapi not found contentTypes.
I console log in directory: plugins/admin/src/components/<Component_Name>.js
I find in Roles of Setting has: /content-manager/collection-types/:model
I try call API with axios (query with Auth): http://localhost:1337/content-manager/collection-types/:model, method GET
=> get all data.
I see api get all model: http://localhost:1337/content-manager/content-types
Notes: get Token: import { auth } from ‘strapi-helper-plugin’; auth.getToken();
@minhtri I thought you were trying to access the content types from the backend.
But as you described you are trying to access this information from the frontend.
Doing that you would have to make an API call, from the frontend.
Have you figured it out? Or do you still need some guidance?
I found solution for it. Thanks @boaz .
Do you have any method that would allow me to inject the contentTypes into the react component? Looking for a way to show some relations in the UI
You will have to define a route in your plugins backend, which will return this value.
Then in the frontend you can query the route like so
Import { request } from ‘strapi-helper-plugin’;
Const contentTypes = await request(‘/custom-plugin-route’);
That would be for custom plugins, but what if I just want to query basic collection types such as pages
, I would do something like
const contentTypes = await request(‘/admin/plugins/content-manager/collectionType/application::pages.pages’);
Right? But I don’t think that works
EDIT: Nevermind I got the URl wrong it should be something like content-manager/collection-types/application::pages.pages?page=1&pageSize=10&_sort=title:ASC&_locale=en-UK
@boaz Thanks