Generate data using a button and display it #448
-
Is it possible to use a Meta Bind button to generate something like a random string (or more complex data) then display it in a text view? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've finally figured out how to store variables in-memory and display them. To assign or read the properties using JavaScript (inside buttons or // Get access to the Meta Bind API
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
// Function to read a memory bind target
const getProperty = (name) => mb.getMetadata(mb.parseBindTarget(`memory^${name}`, context.file.path));
// Function to write a memory bind target
const setProperty = (name, value) => mb.setMetadata(mb.parseBindTarget(`memory^${name}`, context.file.path), value);
// Write the property
setProperty('my_property', 'test'); Then to display this property, I do something like this: |
Beta Was this translation helpful? Give feedback.
I've finally figured out how to store variables in-memory and display them.
For anyone who might struggle with this, the solution is to store properties using a memory bind target. The advantage of using this approach is that nothing is stored permanently in frontmatter making it convenient for non-persistent variables (like random numbers or calculations based on fields).
To assign or read the properties using JavaScript (inside buttons or
meta-bind-js-view
blocks), I use the following code: