How to create a language switcher with DocTypeGrid editor and UmbracoViewPage<IPublishedElement>
I'm quite new to Umbraco and want to implement a language switcher with a component approach. Therefor I used DocTypeGrid editor, and a doc type that is generated by the modelbuilder as being of type PublishedElement.
Now I want to render a language switcher. On the guides that I could, find people instruct to use the Model.Url(...) method. Unfortunatly that is not available on my Model in my cshtml with @inherits UmbracoViewPage<IPublishedElement>.
How would I be able to retrieve the url of the current content item in a specific culture? Can I access the content page that contains the component?
OK, typical ... hours of searching, nothing, 5 minutes after posting my question, I found a possible solution. Would you think this is correct?
var languageService = Current.Services.LocalizationService;
var assignedContentItem = Umbraco.AssignedContentItem;
@foreach (var language in languageService.GetAllLanguages())
{
assignedContentItem.Url(language.CultureInfo.TwoLetterISOLanguageName) }
How to create a language switcher with DocTypeGrid editor and UmbracoViewPage<IPublishedElement>
I'm quite new to Umbraco and want to implement a language switcher with a component approach. Therefor I used DocTypeGrid editor, and a doc type that is generated by the modelbuilder as being of type PublishedElement.
Now I want to render a language switcher. On the guides that I could, find people instruct to use the Model.Url(...) method. Unfortunatly that is not available on my Model in my cshtml with
@inherits UmbracoViewPage<IPublishedElement>
.How would I be able to retrieve the url of the current content item in a specific culture? Can I access the content page that contains the component?
OK, typical ... hours of searching, nothing, 5 minutes after posting my question, I found a possible solution. Would you think this is correct?
Hi
I would say that the services are not a best way to use in page load. They are quite slow.
Try to use UmbracoHelper.
Thanks, Alex
Hi Alex,
thank you for your advice. How would I be able to access the languages in my example using the UmbracoHelper? Can you give me an example please?
is working on a reply...