thanks for all reply, my site use for group has 13 branch companies,each has a newsCenter, and some high level(like ceo or cto etc.) need to read 2 or more newsCenter, so I have to merger this newsCenter to one, then I can sort or do something paging or first news has first css, if not merger to one , when I do paging or get first or last will get wrong Position(), like this:
foreach(var newsCenter in newsCenters)
{
foreach(var news in newsCenter.Children)
{
if(news.IsFirst())
{ Response.Write("first"); }
}
}
you will get two "first", why? because newsCenter1's news1.IsFirst() == true and newsCenter2's news1.IsFirst() == true, so why i must merger two newsCenter to one nodes
how to merger DynamicNode
1.I get two dynamicNodes as the same doctype
like this
var newsCenter1 = homePage.newsCenter.First();
var newsCenter2 = homePage.newsCenter.Last();
how can i merger this to one?
like
var allNewsCenter = newsCenter1 + newsCenter2
2.how to get position in foreach?
3.how to end a method?
like this
@helper RenderNews(string ranges) {
}
I try this but will get a exception and can't exit method
thanks a lot 谢谢
Hi Yumin,
Try this:
var newsCenter1 = homePage.newsCenter.First();
var newsCenter2 = homePage.newsCenter.Last();
var nodes = Model.NodeById(newsCenter1 .Id, newsCenter2.Id);
foreach(var node in nodes){
//Get Position
@node.Position();
}
references:
http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.aspx
http://our.umbraco.org/documentation/Cheatsheets/DynamicNodeRazor.pdf
Marcio, Model.NodeById does not take 2 paramters does it?
Yumin what are you trying to achieve? Why are you trying to merge to Nodes? If feels like you are doing something wrong.
Charlie :)
Sorry my mistake. Is NodesById method that takes as a parameter ids and not NodeById.
Fixing:
var newsCenter1 = homePage.newsCenter.First();
var newsCenter2 = homePage.newsCenter.Last();
var nodes = Model.NodesById(newsCenter1.Id, newsCenter2.Id);
foreach(var node in nodes){
//Get Position
@node.Position();
}
I still dont see the point in doing this? And what version of umbraco are you using?
If you want to get the children of a parent node just do a foreach around children of the parent
foreach(Node contextNode in Node.children)
{
do work
}
I understood that yumin have more than one NewsCenter document type and want to display the first and last. Now it's wait and see if it is.
thanks for all reply, my site use for group has 13 branch companies,each has a newsCenter, and some high level(like ceo or cto etc.) need to read 2 or more newsCenter, so I have to merger this newsCenter to one, then I can sort or do something paging or first news has first css, if not merger to one , when I do paging or get first or last will get wrong Position(), like this:
so i can do anything i want, this why i want merger , i don't know if has a better way solve the problem
hope you can understand, I did't learn english well because the teacher is not pretty ^_^
Hi there,
Has this threat been solved ?
In your loop you can do something like
May be this wil help you http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/IsHelpers
hi fuji,
you will get two "first", why? because newsCenter1's news1.IsFirst() == true and newsCenter2's news1.IsFirst() == true, so why i must merger two newsCenter to one nodes
marcio's method can solve this problem
thanks very much
and anybody knows how to end a method use return?
I tried to code like this but not use
it will get a exception
Can you please show what will be your end result in html ?
is working on a reply...