Doing something wrong with Metadata Template

Started by Redinstead, October 07, 2025, 01:40:56 AM

Previous topic - Next topic

Redinstead

I'm attempting a very basic, and first metadata template. Essentially I'm trying to populate keywords wherever I have a photo with entries in the People category. It's writing the lightroom hierarchical subject and the tag is filled from:

Person|{File.Persons.Tag}

It seems to work, but if there is a second face in the photo then the second name is the single leaf, rather than hierarchical.

So I get:

Person|John Smith
Jane Doe

Rather than:

Person|John Smith
Person|Jane Doe

It took me a while to even find the variable so it might even be as simple as me choosing the wrong one, but any help is appreciated. 

Ideally I would be using the function in the Person Editor to fill in the keywords, but that's going to take me a long time to go through all the people individually, so I thought I could do it this way initially and then do the keywording in the People Editor over time (unless there's a way to "seed" that initially somehow).

In a perfect world I'd not be adding the keywords at all, but I need to to make them searchable in an online storage that doesn't recognise the PersonInImage metadata (or similar).

Tveloso

Since this is a repeatable tag, you'll need to use the foreach formatting function, along with prefix, in order to add the "Person|" string to each element.  You'll also need to then add the list separator "manually", via the postfix function, in order to "reassemble" the value that the variable emits...restoring its repeatable nature.  

This variable:

{File.Persons.Tag|foreach:{value|prefix:Person~|;postfix:~;}}
...may do what you need.

You should of course test it out in the VarToy app, and also test the MD Template that uses it, on just a few files.  I'm pretty sure you'll also need to set the "Merge with existing contents" option on the MD Template.
--Tony

Mario

#2
Looks good to me! Thanks for sharing your solution.

Repeatable tags (tags which can have a list of values) always add a bit of complexity.
Maybe consider using the .Label instead of .Tag, depending on your needs and how you setup labels and tags for your persons.

Notice how the escape character ~ is used for the | and ; because these characters have special meanings for variables. To use them literally, they must be escaped with a ~.  See Literal Text in the help system.

Redinstead

This seems to work perfectly on a test group - thank you so much Tveloso. I have taken what you said as well, Mario, and tweaked it to be confirmed labels.

A lot to learn on my part, obviously, but this is doing exactly what I need just now. I'll test some more post-work and then apply to a larger group.

Much appreciated!

axel.hennig

I think this adds a ';' at the end. If this is not wanted maybe try:

{File.Persons.Tag|foreach:{value|prefix:Person~|}{remaining|is:0,,~;}}

Mario

I think the trailing ; does not matter for MD templates.

Tveloso

After seeing Axel's suggestion about using the "remaining" function in order to treat the last element differently (to omit the trailing semicolon there), I consulted the help to learn about that.

I found that the syntax I used for the special {value} variable, was not actually in keeping with the examples given in the help.  I used formatting functions inside the {value} variable, but that variable can be "immediately closed", and the "Person|" and ";" strings can instead be given directly, as literals, at the level of the foreach function (where the {value} variable lives), placed both before and after the {value} variable...so we don't really need the prefix and postfix functions in this case.

I imagine that the syntax I used still worked, and is technically valid, since the special {value} variable follows all the same parsing rules as any other variable, but instead of doing this:

{File.Persons.Tag|foreach:{value|prefix:Person~|;postfix:~;}}
...the variable can be written a little more concisely, like this:
 
{File.Persons.Tag|foreach:Person~|{value}~;}
Or to use Axel's version, instead of this:

{File.Persons.Tag|foreach:{value|prefix:Person~|}{remaining|is:0,,~;}}
...we can do this:

{File.Persons.Tag|foreach:Person~|{value}{remaining|is:0,,~;}}(the "prefix text" is added as a literal, and the remaining function handles the "postfix text" - i.e. the delimiter - omitting it from the last element)

Mario indicated above that in this case it doesn't matter that the trailing delimiter is included, but there are of course cases where the last element of something would need different treatment...
--Tony