# Insert tag based on file path

**URL:** <https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127>\
**Category:** Help\
**Tags:** templater\
**Created:** [March 10, 2026, 5:41pm UTC](https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127 "2026-03-10T17:41:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevDog](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kevdog/32/68630_2.png) [@KevDog](https://forum.obsidian.md/u/KevDog)\
**Post date:** [March 10, 2026, 5:41pm UTC](https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127/1 "2026-03-10T17:41:10Z")

</div>

### What I’m trying to do

Based on the file path, I would like Templater to add a file tag. In pseudocode  
inSdlc = filePath includes “SDLC”  
add “sdlc” to file tags

### Things I have tried

I suspect I might need to use tp frontmatter to get the desired results, but my experiments there didn’t go any better.

---

<div class="post-metadata">

**Author:** ![KevDog](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kevdog/32/68630_2.png) [@KevDog](https://forum.obsidian.md/u/KevDog)\
**Post date:** [March 10, 2026, 5:43pm UTC](https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127/2 "2026-03-10T17:43:45Z")

</div>

Forgot to paste the code I was using:  
`<%* await`  
`if(tp.file.path(1).includes("Coverage Areas/SDLC")) tp.file.tags.push("sldc")`  
`_%>`

---

<div class="post-metadata">

**Author:** ![ReaderGuy42](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@ReaderGuy42](https://forum.obsidian.md/u/ReaderGuy42)\
**Post date:** [March 11, 2026, 1:05pm UTC](https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127/3 "2026-03-11T13:05:51Z")

</div>

Have you tried the `Folder templates` in Templater? You’d need a template for each folder, which isn’t as elegant as just having a line of code, I guess, but you could have templates for each folder, and then the only difference would be the tag.

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [June 9, 2026, 1:06pm UTC](https://forum.obsidian.md/t/insert-tag-based-on-file-path/112127/4 "2026-06-09T13:06:23Z")

</div>

Closed on June 9, 2026, 1:06pm UTC

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