The first response from @AlanG in https://forum.obsidian.md/t/templater-get-the-parent-folder-name/47241 should pretty much get you there.
If you have:
[folder] VaultRoot
- [folder] Client
- [folder] Project
- [file] Note
- [folder] Project
And you run the following Templater template when the Note is active:
<%*
const folders = tp.file.folder(true).split('/'); //breaks the folder path into an array
const project = folders[folders.length - 1]; //gets the last element of the array
const client = folders[folders.length -2]; //gets the second to last element of the array
-%>
Then the variable project will have the value of Project and the variable client will have the value of Client.
If you want to apply these values to the note’s frontmatter, then your template should look like:
<%*
const folders = tp.file.folder(true).split('/');
const project = folders[folders.length - 1];
const client = folders[folders.length -2];
-%>
---
client: <% client %>
project: <% project %>
---
Please be aware that the above assumes you’re running the template on an empty/new note or you’ve positioned the cursor to the very beginning of an existing note.