This append scripts to your current screen and use a table to store them.
Embed js scripts from your databse into your app
Find out more about Budibase.
Create a table with the following columns:
-
content (text) A valid URL pointing to a JS file or JS code with handlebars
-
collection (options or text) Collection name to group scripts
-
parent (options with values: head, body, component) Where the script should be appended
-
inBuilder (boolean) Does the script execute in Builder
Add the component, select your newly created table and filter by collection name if needed.
You can expose values to the handlebars context via the Context Object.
Example value
return { CurrentUser: $("Current User.email"), search: $("State.search_text")};
Then use {{ CurrentUser }} in your script's content
To add Google Analytics tracking
Row 1 (loading external script):
content: https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXX
collection: analytics
parent: head
inBuilder: false
Row 2 (init gtag object):
content: window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXX');
collection: analytics
parent: body
inBuilder: false
- Handlebars are parsed but can't access the live Budibase context
To build your new plugin run the following in your Budibase CLI:
budi plugins --build
You can also re-build everytime you make a change to your plugin with the command:
budi plugins --watch