November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Oops, here's the code formatted:
protected HomePage HomePageData { get { return ContentRepository.Get<HomePage>(PageReference.StartPage); } }
To something like:
protected UpcomingEventsBlock UpcomingEventsData { get { return ContentRepository.Get<UpcomingEventsBlock>(contentLink); } }
Sorry Bob, I realize I've not been clear on that.
I've not been able to find the correct parameter for the ContentRepository.Get method. There is no Block equivalent to the PageReference class, that I can find. I've tried a large number of variations but I'm mostly flailing in the dark.
If you could point me to relevant documentation or examples that would be a huge help.
Thanks
Thanks Johan, that sounds good, but I was not able to get it to work with any of ContentReference's methods, such as StartPage or RootPage.
This makes me realize that the original home page code is not a good model to follow. PageReference.StartPage, as far as I understand it, is a global kind of reference, a 'hard coded' pointer to the home page. The code I'm trying to move over to a block is doing a data bind for the child blocks:
rptSlider.ItemDataBound += BindEvents; if (UpcomingEventsData.ThisWeekEvents != null && UpcomingEventsData.ThisWeekEvents.Count > 0) { var allEvents = UpcomingEventsData.ThisWeekEvents.FilteredItems .Select(content => ContentRepository.Get<HomePageEventBlock>(content.ContentLink)) .Cast<IFeaturedEvent>().ToArray(); var groupings = new List<FeaturedEventGrouping>(); var curGrouping = new FeaturedEventGrouping(); for (int curIndex = 0; curIndex < allEvents.Count(); curIndex++) { var curEvent = allEvents[curIndex]; curGrouping.Events.Add(curEvent); if (curGrouping.IsFull || curIndex == allEvents.Count() - 1) { groupings.Add(curGrouping); curGrouping = new FeaturedEventGrouping(); } } rptSlider.DataSource = groupings; rptSlider.DataBind(); }
Where the UpcomingEventsData property is pointing to the container block.
Found it! Thanks to Dan Matthews and Alf Nilsson The key was in this thread:
http://world.episerver.com/Forum/Developer-forum/EPiServer-7-CMS/Thread-Container/2013/7/Block-ContentReference-ID/
"If you cast CurrentBlock to IContent you will be able to access data from the IContent Interface."
So now I have:
protected UpcomingEventsBlock UpcomingEventsData { get { var contentLink = (CurrentBlock as IContent).ContentLink; return ContentRepository.Get<UpcomingEventsBlock>(contentLink); } }
And it works like a charm.
I've inherented an Episerver website, making me a newbie once again. My current task is to move a slider type content area off of a page template into a "block with blocks" configuration, in order to have more granular content scheduling for that page.
I'm stuck trying to move the property that points to the page data:
protected HomePage HomePageData(PageReference.StartPage);
{
get
{
return ContentRepository.Get
}
}
Into something that points to the containing block data, for example:
protected UpcomingEventsBlock UpcomingEventsData(contentLink);
{
get
{
return ContentRepository.Get
}
}
Thanks,
Mark