Consume PHP variable
Last updated
Was this helpful?
Last updated
Was this helpful?
Sometimes it is needed to consume PHP variables in your frontend TypeScript coding. You are covered! The boilerplate comes with a mechanism to get a typed object.
If you have a look at you will find a typed OptionStore
. You also notice that it extends from BaseOptions
. The boilerplate comes out-of-the-box with important variables you can already use:
The OptionStore
can be used by React in that way (it relies to the context factory):
To make it available in TypeScript we need to adjust the OptionStore#others
property:
Let's access it:
It can also read directly (relies on the root store ):
Assume we want to know if the user is allowed to install plugins (install_plugins
). Adjust the method and additionally make the variable only be exposed for a given context (site, admin):