Hey there!
I am trying to create a ‘button template’ so I can reuse a button in multiple places using the inline button plugin. I have created the button using dataviewjs and calling the functions from the button plugin.
How can I get it to show up in the command pallette when I want to add an instance to it?
I have a feeling it is something to do with it looking for block-language-button
in the div when it is actually block-language-dataviewjs
Things I have tried
- adding the
^button-new-journal-entry
underneath - passing the id as an
arg:
See code below:
const { createButton } = this.app.plugins.plugins["buttons"];
const year = moment(Date.now()).format("YYYY");
const month = moment(Date.now()).format("MMMM");
const fileName = moment(Date.now()).format("DD-MM-YY - dddd");
const clickHandler = async () => {
const currentEntry = this.app.vault.getAbstractFileByPath(
`Personal/Journal/Entries/${year}/${month}/${fileName}.md`
);
if (currentEntry) {
app.workspace.activeLeaf.openFile(currentEntry);
} else {
//check if the year and month folders exist, if not create them
const yearDir = await this.app.vault.getAbstractFileByPath(
`Personal/Journal/Entries/${year}`
);
if (!yearDir) {
await this.app.vault.createFolder(
`Personal/Journal/Entries/${year}`
);
}
const monthDir = await this.app.vault.getAbstractFileByPath(
`Personal/Journal/Entries/${year}/${month}`
);
if (!monthDir) {
await this.app.vault.createFolder(
`Personal/Journal/Entries/${year}/${month}`
);
}
const newEntry = await this.app.vault.create(
`Personal/Journal/Entries/${year}/${month}/${fileName}.md`,
""
);
app.workspace.activeLeaf.openFile(newEntry);
}
};
createButton({
app,
el: this.container,
args: { name: "📔 New Journal Entry", class: "custom-button" id: "button-new-journal-entry"},
clickOverride: { click: clickHandler, params: [] },
});