I'm running into a problem with a multi language site and I can't find a solution for it.
In the content tab I want the stucture like this:
Home EN | |-- news | Home NL | |--news | News Items | |--news item |--news item 2 |--news item 3
The news item content has to be visible on the news page.
The goal is to put all news items in one place and with and make them visible on the languages that the user picks with a datatype. The problem isn't the datatype but I cant find how to get to the news items using a partial view macro. CurrentPage.AncestorOrSelf(1) gives me the Rootnode but I can't find a way to go beond that.
I hope the problem is clear. If not feel free to ask more questions.
@jivan, I tried your method. I like the fact that it doesn't use a hardcoded id so the customer can't screw it up. The variable however stays empty. I don't get why...
@ Alex, You have put me in the right direction for the solution. I used Umbraco.TypedContent(id); About the reason for the site structure. our customer doesn't want to translate every news item in every language. He want's to choose what language shows witch news item.
So I have a working solution now but I'm still interested in a way to search on documtentypealias.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var root = CurrentPage.AncestorOrSelf(1);
const string newsAlias = "News";
string rootLanguage = root.language;
int catId = -1;
Int32.TryParse(Request.QueryString["Category"], out catId);
@* find 'News Items' node*@
var news = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias.Equals(newsAlias));
var newsItems = news.DescendantOrSelf("NewsItems");
string leftRight = "left";
HashSet<int> CurrentLanguageNewsItems = new HashSet<int>{};
HashSet<string> CurrentLanguageCategories = new HashSet<string>{};
if (newsItems != null)
{
foreach (var newsItem in newsItems.Children.Where("visible"))
{
int currentNodeId = newsItem.Id;
var currentNodeContent = Umbraco.Content(currentNodeId);
if(Array.IndexOf(currentNodeContent.showInLanguage.Split(','), @rootLanguage) >= 0)
{
CurrentLanguageNewsItems.Add(@currentNodeId);
foreach(var category in currentNodeContent.category.Split(','))
{
CurrentLanguageCategories.Add(@category);
}
}
}
}
@* build news category navigation*@
string currentClass = "class=current";
<div class="subNav">
<ul id="labelMenu" class="clear">
<li @if(@catId < 1000 ){@currentClass}><a href="/news">All news</a></li>
@foreach (string langCategory in CurrentLanguageCategories)
{
var currentLangCat = Umbraco.Content(@langCategory);
<li @if(@catId == @currentLangCat.Id){@currentClass}>
<a href="/[email protected]">
@switch (@rootLanguage)
{
case "EN":
@currentLangCat.EN
break;
case "NL":
@currentLangCat.NL
break;
}
</a>
</li>
}
</ul>
</div>
@* Get news items with correct language and correct catergory*@
<div class="newsItems">
@if (newsItems != null)
{
foreach (int newsItem in CurrentLanguageNewsItems)
{
int currentNodeId = newsItem;
var currentNodeContent = Umbraco.Content(currentNodeId);
if( (catId < 1000) || ( (catId >= 1000) && (Array.IndexOf(currentNodeContent.category.Split(','), @catId.ToString()) >= 0) ) ){
<section class="section contentBlock @leftRight clear">
<div class="contentBlockText pad">
<ul class="itemLabels clear">
@foreach (string itemCategories in currentNodeContent.category.Split(',')){
<li>
@switch (@rootLanguage)
{
case "EN":
@Umbraco.Content(@itemCategories).EN
break;
case "NL":
@Umbraco.Content(@itemCategories).NL
break;
}
</li>
}
</ul>
<h2>@currentNodeContent.newsTitle</h2>
<div class="textIntro clear">
@currentNodeContent.newsText
</div>
@if(@currentNodeContent.extendedText.ToString() != "")
{
<div class="extendedText clear">
@currentNodeContent.extendedText
<a href="#" class="readMore medium large">Read more</a>
</div>
}
</div>
@if((@currentNodeContent.newsImage).ToString() != ""){
}
</section>
switch (@leftRight){
case "left":
leftRight = "right";
break;
case "right":
leftRight = "left";
break;
}
}
}
}
</div>
}
As you'll notice I need a to get to the content with the Umbraco helper. This seems awkward and gives me heeps of trouble when getting the images. Is there a way to simplify this?
Another thing that's bothering me is the two switches I have to use. The rootLanguage string in the beginning gives me the country code. I wanted to make it work like @currentLanguageCat.@rootLanguage But that of course doesn't work.... I'd like to be able to leave the script alone if I have to add a language.
Bare in mind, I'm a front-end developer and have been actively working with Umbraco for the past year. Before that I had no MVC C# experience whatsoever. If you see things that are not as neat as can be, please feel free to comment.
Shared content between languages
Hi all,
I'm running into a problem with a multi language site and I can't find a solution for it.
In the content tab I want the stucture like this:
Home EN
|
|-- news
|
Home NL
|
|--news
|
News Items
|
|--news item
|--news item 2
|--news item 3
The news item content has to be visible on the news page.
The goal is to put all news items in one place and with and make them visible on the languages that the user picks with a datatype. The problem isn't the datatype but I cant find how to get to the news items using a partial view macro.
CurrentPage.AncestorOrSelf(1) gives me the Rootnode but I can't find a way to go beond that.
I hope the problem is clear. If not feel free to ask more questions.
Thanks a lot
Hi Frans,
Interesting structure for the site. How will you manage multilingual issue on the news item ?
Try to solve your problem using UmbracoHelper and id of the NewsItems node.
var newsItemsParent = helper.TypedContent(1212); newsItemsParent.Children();
Thanks
This may help you.
Goodmorning,
@jivan, I tried your method. I like the fact that it doesn't use a hardcoded id so the customer can't screw it up. The variable however stays empty. I don't get why...
@ Alex, You have put me in the right direction for the solution. I used Umbraco.TypedContent(id); About the reason for the site structure. our customer doesn't want to translate every news item in every language. He want's to choose what language shows witch news item.
So I have a working solution now but I'm still interested in a way to search on documtentypealias.
@Frans sorry, it was my fault.
should be
, since its the content. I am stupid.
Hi Jivan,
You are most cirtainly not stupid! You've brought me the perfect solution. I have read over it multiple times and I didn't see it too.
Thanks a lot!
Kind regards,
Frans
What I have now is this:
As you'll notice I need a to get to the content with the Umbraco helper. This seems awkward and gives me heeps of trouble when getting the images. Is there a way to simplify this?
Another thing that's bothering me is the two switches I have to use. The rootLanguage string in the beginning gives me the country code. I wanted to make it work like
@currentLanguageCat.@rootLanguage
But that of course doesn't work.... I'd like to be able to leave the script alone if I have to add a language.Bare in mind, I'm a front-end developer and have been actively working with Umbraco for the past year. Before that I had no MVC C# experience whatsoever. If you see things that are not as neat as can be, please feel free to comment.
Thanks
is working on a reply...