https://discord.umbraco.com logo
#help-with-umbraco
Fallback for `.Name()` ?
# help-with-umbraco
g

greystate

02/02/2024, 11:06 AM
How do I ask for a node's
.Name()
in the current culture, but with a fallback to e.g. English, if it doesn't exist in the current language? Is it even possible? There is an overload that allows asking for a specific culture, with fallback to "current", but I need the opposite... 😬
j

jespermayntzhusen

02/02/2024, 11:11 AM
Doesn't look like the name property has super smart fallback methods, why not just try to get it with the current culture, nullcheck and then try in the other culture? e.g.
Copy code
csharp
var name = CurrentPage.Name() ?? CurrentPage.Name("en-US") ?? "";
g

greystate

02/02/2024, 11:13 AM
That's actually what I'm trying now 😁 - just always hope there's something more "correct" :D
k

kdxperbol

02/02/2024, 11:56 AM
"cloud?" 🙂
Do the "fallback language" settings affect this somehow? I forget what OotB support you get from the language fallback settings...
g

greystate

02/02/2024, 12:40 PM
I don't know why or how "cloud" ended up there 😁 I didn't even mention it in my question...
s

skttl

02/02/2024, 1:18 PM
You could also do
CurrentPage.Name.IfNullOrWhiteSpace(CurrentPage.Name("en-US"))
in case the name can be empty but not null 🙂
g

greystate

02/02/2024, 1:32 PM
I ended up doing this (doing it for three different pickers):
Copy code
csharp
var fallbackCulture = "en-us";
var materialName = block.Material != null
   ? block.Material.Name() ?? block.Material.Name(fallbackCulture)
   : "(none)";
3 Views