Snippets for specific folder

Hi, I am looking for a way to apply snippets only to notes from a specific folder. I’ve searched for plugins, searched the forums, searched the search engine and haven’t seen anyone having a similar problem.

For example, I don’t want to change the bold color globally, but only in the notes from “daily note”.

Does anyone know if this is possible?

1 Like

i don’t think that’s possible without a plugin/js. each note is like single html file, and afaik it isn’t aware of its path/location.

that said, this plugin will help you. it will virtually apply cssclass to your note based on the note’s path (as long as you have the plugin enabled)

2 Likes

Hi @befree

You can’t do this at the folder level as you would like without a plugin AFAIK. I haven’t tried the plugin @efemkay mentioned but you can do what you want at the file level using “cssclass” in the “Front Matter” without needing a plugin.

If you are using a template to make the daily notes you should be able to include the front matter right in the template.

At the top of your file you would need to add a 3 line block that starts with 3 dashes and ends with 3 dashes and in middle line use the "cssclass: " key followed by the name of the CSS class you want to apply. Like this:

---
cssclass: "customnote1" 
---

If you already have a front matter block just add the cssclass line

then in a CSS Snippet define the Class:

/* FrontmatterCSS.css */
.customnote1 .cm-s-obsidian, 
.customnote1 .cm-strong, 
.customnote1 strong {
  color: #ff0000;
}

Here is an example screenshot using 3 alternate bold colors:

/* FrontmatterCSS.css */
.customnote1 .cm-s-obsidian, 
.customnote1 .cm-strong, 
.customnote1 strong {
  color: #ffff00;
}

.customnote2 .cm-s-obsidian, 
.customnote2 .cm-strong, 
.customnote2 strong {
  color: #00ffff;
}

.customnote3 .cm-s-obsidian, 
.customnote3 .cm-strong, 
.customnote3 strong {
  color: #ff00ff;
}

You can reuse the colors for as many notes as you want, I only used each of them one time in the screenshot to save space.

The only caveat, besides needing to edit each file you want to change, is that the notes using the alternate formatting will have the front matter block showing in them at the top.

2 Likes

Thank you very much, this seems to be the best solution to my problem. Thanks a lot for the great explanation, the screenshots and the time you took to describe it all :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.