Help manipulating strings in expressions or scripts

I am using a horizontal menu to navigate between different sites. I would like to set the menu label to the current site name. I have tried using page.props.path and page.props.primaryview but both of them come with extra fluff that I can’t figure out how to trim off.
Primaryview comes with the whole path so “foldername/anotherfoldername/the part I actually want”
I have tried splitting that with split({value},"/")[0,2] but it says 2 is too long for length 0. I figured the error would go away once it has an actual path to work with, but when implemented it is blank with an error overlay.

I would appreciate any tips.

Script:

# -1 always gives the final item of the array
"foldername/anotherfoldername/the part I actually want".split("/")[-1]

Expression:

split("foldername/anotherfoldername/the part I actually want", "/")[len(split("foldername/anotherfoldername/the part I actually want", "/")) - 1,0]
1 Like