Problem with IPublishedElement in different cultures
Hi all,
I have a very strange issue in Umbraco 8.6.4. I have a class that contains an IPublishedElement and a custom enum for our culture:
public class CultPublishedElement {
public IPublishedElement element { get; set; }
public enCulture culture { get; set; }
}
Then I call this in my method (in a UmbracoApiController):
List<CultPublishedElement> cultureSpecificQuestionMarkers = new List<CultPublishedElement>();
int cultureId = (int)cult;
string cultureCode = cult.ToString().Replace("_", "-");
IPublishedContent tmpGame = Umbraco.Content(game.Id);
List<IPublishedElement> tmpElements = tmpGame.Value<IEnumerable<IPublishedElement>>("fldSpecificQuestions", culture: cultureCode).ToList();
foreach (IPublishedElement tmpElement in tmpElements) {
cultureSpecificQuestionMarkers.Add(
new CultPublishedElement {
element = tmpElement,
culture = cult,
}
);
}
All content is fetched, but when I check a property called 'question' in my IPublishedElement in English first, all other 'questions' are also English. When I first check a 'question' in French, all 'questions' are in French.
So whatever culture I use as the first culture "overrides" all other cultures.
I also tried to fetch the records from another class to see if that helps, but no luck. It seems that the IPublishedElement uses extensive caching or have a reference to each other.
You fill cultureSpecificQuestionMarkers with IPublishedElements from 1 culture, right?
And you get the IPublishedElement by adding culture as parameter, but when you get properties from the element you should provide cultureCode parameter as well:
I I mean by inspecting the object in a watch in Visual Studio.
'You fill cultureSpecificQuestionMarkers with IPublishedElements from 1 culture, right?'
That's right... I have a multiculti IPublishedContent which contains a non-multiculti NestedContent field.
"And you get the IPublishedElement by adding culture as parameter, but when you get properties from the element you should provide cultureCode parameter as well:
For instance: string question = tmpElement.Value
That's exactly what I do.
"And may I ask: what are you trying to achieve with your code? What's the purpose of the list you are generating?"
My DocType is a game with geolocations. The geolocations are non-multiculti nested content items. That's where things go wrong.
Hi Dave,
Let me say this to you, actually values in nested content are independent within culture. That means if you add 5 items in french culture and 3 items in English culture and try to fetch the items by code
This will only populate the results within the specified culture. So if English is passed as parameter you will only get English results for instance only English questions will be returned.
If you want to get the results from each cultures. Just fetch the cultures from the node and perform a loop.
You can fetch culture of the node by following
var cultures = Umbraco.Content(game.Id).Cultures;
And also if you didn't get any results try to pass a fall back parameter , it might pull the results.
Game 1 (NL)
- fldTitle: (Textfield - Varying by culture)
- fldSpecificQuestions: (Nested Content - Varying by culture)
- fldLocation: (Geolocation)
- fldQuestions: (Nested Content - Varying by culture)
- fldQuestion: (Textfield - Varying by culture)
- fldAnswers: (Nested Content - Varying by culture)
- fldAnswer: (Textfield)
- fldScore: (numeric)
Game 1 (EN)
- fldTitle: (Textfield - Varying by culture)
- fldSpecificQuestions: (Nested Content - Varying by culture)
- fldLocation: (Geolocation)
- fldQuestions: (Nested Content - Varying by culture)
- fldQuestion: (Textfield - Varying by culture)
- fldAnswers: (Nested Content - Varying by culture)
- fldAnswer: (Textfield)
- fldScore: (numeric)
So my DocType contains Nested content which is Varying by culture, which contains Nested content which is Varying by culture, which contains Nested content which is Varying by culture.
I think something gets screwed with that. And a Nested content which is Varying by culture within a Nested content which is Varying by culture is totally unnecessary, right?
Problem with IPublishedElement in different cultures
Hi all,
I have a very strange issue in Umbraco 8.6.4. I have a class that contains an IPublishedElement and a custom enum for our culture:
Then I call this in my method (in a UmbracoApiController):
All content is fetched, but when I check a property called 'question' in my IPublishedElement in English first, all other 'questions' are also English. When I first check a 'question' in French, all 'questions' are in French.
So whatever culture I use as the first culture "overrides" all other cultures.
I also tried to fetch the records from another class to see if that helps, but no luck. It seems that the IPublishedElement uses extensive caching or have a reference to each other.
Does anyone have a solution for this problem?
Thanks, Dave
Really? No one? At least i'm not the only one that's confussed about this... :-)
Hi Dave,
What do you mean bij "check a question"
You fill cultureSpecificQuestionMarkers with IPublishedElements from 1 culture, right?
And you get the IPublishedElement by adding culture as parameter, but when you get properties from the element you should provide cultureCode parameter as well:
For instance:
Is this what you do?
And may I ask: what are you trying to achieve with your code? What's the purpose of the list you are generating?
Hi Remko,
'What do you mean bij "check a question"'
I I mean by inspecting the object in a watch in Visual Studio.
'You fill cultureSpecificQuestionMarkers with IPublishedElements from 1 culture, right?'
That's right... I have a multiculti IPublishedContent which contains a non-multiculti NestedContent field.
"And you get the IPublishedElement by adding culture as parameter, but when you get properties from the element you should provide cultureCode parameter as well: For instance: string question = tmpElement.Value
That's exactly what I do.
"And may I ask: what are you trying to achieve with your code? What's the purpose of the list you are generating?"
My DocType is a game with geolocations. The geolocations are non-multiculti nested content items. That's where things go wrong.
Thanks in advance!
Hi Dave, Let me say this to you, actually values in nested content are independent within culture. That means if you add 5 items in french culture and 3 items in English culture and try to fetch the items by code
This will only populate the results within the specified culture. So if English is passed as parameter you will only get English results for instance only English questions will be returned.
If you want to get the results from each cultures. Just fetch the cultures from the node and perform a loop. You can fetch culture of the node by following
And also if you didn't get any results try to pass a fall back parameter , it might pull the results.
I might have found the problem...
This is my IPublishedContent "Game 1":
So my DocType contains Nested content which is Varying by culture, which contains Nested content which is Varying by culture, which contains Nested content which is Varying by culture. I think something gets screwed with that. And a Nested content which is Varying by culture within a Nested content which is Varying by culture is totally unnecessary, right?
Hi Dave.
Yes, it should look like this for it to work properly.
Thank everybody! I completely overlooked the Varying by culture withing the Varying by culture withing the Varying by culture:-)
is working on a reply...