Fallback for `.Name()` ?
# help-with-umbraco
c
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
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") ?? "";
c
That's actually what I'm trying now 😁 - just always hope there's something more "correct" :D
k
"cloud?" 🙂
Do the "fallback language" settings affect this somehow? I forget what OotB support you get from the language fallback settings...
c
I don't know why or how "cloud" ended up there 😁 I didn't even mention it in my question...
s
You could also do
CurrentPage.Name.IfNullOrWhiteSpace(CurrentPage.Name("en-US"))
in case the name can be empty but not null 🙂
c
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)";
4 Views