Skip to content

Instantly share code, notes, and snippets.

// v0.1
// template to use
const templateFolder = "templates";
const templateName = "";
// creating the new file
const newFileFolder = "test/meetings";
const openNewFile = false;
GitMurf / obsidian.templater.query.section.keyword-page-name.js
Created May 30, 2022
When using headings with a [[page name]] in it, create a "search embed query" with all those headings expanded
View obsidian.templater.query.section.keyword-page-name.js
const noteName = tp.file.title;
let queryKeyword = await tp.system.prompt("Keyword for Section search query (do NOT add [ ] brackets around it)", noteName);
if(queryKeyword) {
// Un-comment the next line if you want the keyword to require [] brackets around it for backlinks matching purposes
queryKeyword = `\\[\\[${queryKeyword}[\\|\\]]`; // the | pipe check accounts for alias links
tR = `
# Keyword Section Query
View obsidian.templater.other.get-all-links-and-backlinks.js
let startDate = await tp.system.prompt('Start Date');
let endDate = await tp.system.prompt('End Date');
const nlDatesPlugin = app.plugins.getPlugin('nldates-obsidian');
function getNldDate(nlDatesPlugin, dateString) {
let parseResultLink = null;
let parseResult = nlDatesPlugin.parseDate(dateString);
if(parseResult){ parseResultLink = parseResult.formattedString };
if(parseResultLink === "Invalid date") { parseResultLink = null }
View obsidian.templater.editor.selection.turn-into-callout.js
//Set to false if you do NOT want to ask for a custom title or whether foldable or not
const bCustomTitle = true;
const bFoldable = true;
const calloutOptions = ['note', 'abstract', 'summary', 'tldr', 'info', 'todo', 'tip', 'hint', 'important', 'success', 'check', 'done', 'question', 'help', 'faq', 'warning', 'caution', 'attention', 'failure', 'fail', 'missing', 'danger', 'error', 'bug', 'example', 'quote', 'cite'];
let calloutType = await tp.system.suggester(calloutOptions, calloutOptions, false);
if(!calloutType) { return };
calloutType = calloutType.toUpperCase();
const search = app.workspace.getLeavesOfType("search")[0];
let keyword = await tp.system.prompt('Keyword', '[' + '[Journal');
keyword = keyword.replace(/(\[|\])/g, "\\$1");
const searchQuery = `section:(/^#+ ${keyword}.*\\n+\\S[\\s\\S]*[^\\n]/) OR section:(/^#+ ${keyword}.*/ section:(/[\\s\\S]*[^\\n]/))`;
//Collapse=true, Expand=false
//Show Extra Context: true or false
//SortOrder Options: alphabeticalReverse, alphabetical, byModifiedTime, byModifiedTimeReverse, byCreatedTime, byCreatedTimeReverse
View obsidian.templater.plugins.hover-editor.tile-popover-windows-grid.js
//This one tiles popovers with a window grid approach
let hoverPlugin = app.plugins.plugins["obsidian-hover-editor"];
let curPopovers = hoverPlugin ? hoverPlugin.activePopovers : [];
let defaultHeight = "47vh";
let defaultWidth = "32vw";
const defaultLeft = 35;
const defaultTop = 25;
let gridScenario = 1;
View obsidian.templater.operation.change-new-file-location.js
//Specify your typical default location here so it is always top of the list to reset to
const myDefaultLocation = "new";
//Specify the list of folders you would like to have an option to switch between
const changeToPaths = [myDefaultLocation, 'new/tasks', 'templater', '/'];
const folderTypeSetting = app.vault.getConfig('newFileLocation');
if(folderTypeSetting !== "folder") {
new Notice(`It appears you currently are not using the setting to specify a folder to save new notes to.`, 10000);
} else {
View .cm-preview-code-block .internal-query .search-results-children .query-emoji,
.popover.hover-popover > .markdown-embed .markdown-preview-section .internal-query .search-results-children .query-emoji {
font-size: 2em;
margin-top: 20px;
display: block;
} .cm-line .query-emoji > span,
.popover.hover-popover > .markdown-embed .markdown-preview-section > div > :not(.internal-query) .query-emoji > span {
display: none;