Using page fields in widgets
-
In html code widget whether it is possible to use resource variables? Such as name, description. It would be very convenient! I'm pretty sure that will not be difficult to do this with the help of the plugin, but I still want make sure.
-
It would be desirable to be able to indicate the field values in widgets, for example:
<h1>\{name\}<h1> <p>\{description\}</p>
-
@a_5mith yes! )
-
As long as the information you want is in the API for that page, then yes, you can. You can do either the page you're on with single brackets, so this topic for example was started by {posts.editor.username} and is the {posts.pid}nd post made.
Or you can use two brackets per side to access anything from the config api. Which is found by going to https://community.nodebb.org/api/config/.
The API for this topic is https://community.nodebb.org/api/topic/4164/using-page-fields-in-widgets, if you paste all of that into jsonlint.com, you will see the hierarchy.
So look at posts, then user, then username, then look at what I typed, notice the full stops.
So this will only work on the page the widget is being displayed on. So you can't for example add post information on the home page.
Almost every page has an api, you access the data by adding /api/ immediately after your domain name, before the rest of the URL.
-
@a_5mith
\{posts.editor.username\}
not work in widgets -
This post is deleted!
-
@sergej-saveljev said:
@a_5mith
\{posts.editor.username\}
not work in widgetsIs that available in the api on the page you're viewing the widget on. I'm pretty sure that's how it works. Pinging @psychobunny as it's his templates.js.