# "if" in path format - I don't get the syntax

**URL:** <https://discourse.beets.io/t/if-in-path-format-i-dont-get-the-syntax/2389>\
**Category:** Help\
**Created:** [August 27, 2023, 5:55pm UTC](https://discourse.beets.io/t/if-in-path-format-i-dont-get-the-syntax/2389 "2023-08-27T17:55:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Carl](https://discourse.beets.io/u/Carl)\
**Post date:** [August 27, 2023, 5:55pm UTC](https://discourse.beets.io/t/if-in-path-format-i-dont-get-the-syntax/2389/1 "2023-08-27T17:55:47Z")

</div>

Hello,

there is a “%if{condition,text}” function in beets ([https://beets.readthedocs.io/en/stable/reference/pathformat.html](https://beets.readthedocs.io/en/stable/reference/pathformat.html)), but I can’t work out the correct syntax.

What I want to get: I want to _not_ have the “albumtype” in the new path if it is “album”, but I _want_ to have " ($albumtype)" in the path if it is “ep” or “single”. Like this:  
~/music/Beatles, The/Please Please Me/  
~/music/Beatles, The/Twist and Shout (ep)/  
(“Please Please me” is an album, “Twist and Shout” is an EP)

I started with EPs only to keep the syntax simple:

```auto
paths:
    default: %the{$albumartist}/$album%if{albumtype:ep, ($albumtype)}/$track - $title

```

… but that way I also get the albumtype for albums, not only for EPs:  
~/music/Beatles, The/Please Please Me (album)  
~/music/Beatles, The/Twist and Shout (ep)

The same with:

```auto
    default: %the{$albumartist}/$album%if{albumtype=ep, ($albumtype)}/$track - $title
    default: %the{$albumartist}/$album%if{albumtype==ep, ($albumtype)}/$track - $title
    default: %the{$albumartist}/$album%if{albumtype:'ep', ($albumtype)}/$track - $title
    default: %the{$albumartist}/$album%if{albumtype='ep', ($albumtype)}/$track - $title
    default: %the{$albumartist}/$album%if{albumtype=='ep', ($albumtype)}/$track - $title

```

What do I have to do to get the albumtype in my path only for EPs and Singles?

Thanks for your help!

Carl

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [August 27, 2023, 7:05pm UTC](https://discourse.beets.io/t/if-in-path-format-i-dont-get-the-syntax/2389/2 "2023-08-27T19:05:56Z")

</div>

This is admittedly not intuitive, but [the docs](https://beets.readthedocs.io/en/stable/reference/pathformat.html#template-functions) do have a definition:

> - `%if{condition,text}` or `%if{condition,truetext,falsetext}`: If `condition` is nonempty (or nonzero, if it’s a number), then returns the second argument. Otherwise, returns the third argument if specified (or nothing if `falsetext` is left off).

That means that `condition` is not an expression, a beets query, or anything else smart. It’s just text. So the only useful thing you can put in there is, like, a field reference or another template function that expands to something empty/nonempty (or zero/nonzero). For example, `%if{$foo,hello,goodbye}` expands to `hello` if the `foo` field is nonempty and `goodbye` otherwise.

If you want to do some fancy logic for the condition, people often combine this with the `inline` plugin to define a useful “condition field” that they then use in an `%if`.

---

<div class="post-metadata">

**Author:** ![Carl](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Carl](https://discourse.beets.io/u/Carl)\
**Post date:** [August 27, 2023, 9:24pm UTC](https://discourse.beets.io/t/if-in-path-format-i-dont-get-the-syntax/2389/3 "2023-08-27T21:24:19Z")

</div>

Ah, I see. The following did what I wanted to get:

```auto
plugins: inline the

import:
    copy: yes
    write: yes

paths:
    default: %the{$albumartist}/$album$printalbumtype/$track - $title

item_fields:
    printalbumtype: u' (EP)' if albumtype == 'ep' else u' (Single)' if albumtype == 'single' else u''

```

Thank you!

Carl
