Access a page property from a block in a content area

Vote:
 

Hi there,

I'm sure this must be easy but I haven't been able to find out how to do it. I have a page with start and end date properties and a content area that can contain mutliple blocks but which must be all of the same type. Each instance of the block on the page needs to use the start and end date properties of the page in order to do some processing. I don't want properties of start and end on each block instance as each block needs to use the same start and end. How do I access the start and end date properties from the page when in the block?

For info this is MVC.

Thanks in advance,

Mark

#131344
Jul 21, 2015 13:46
Vote:
 

Hi, Mark,

If I understood you correctly, you want to get the page where your blocks reside on (inside a contentarea).

To do that, you can use PageRouteHelper,  check out the code bellow:

var pageRouteHelper = ServiceLocator.Current.GetInstance<PageRouteHelper>();
var currentPage = pageRouteHelper.Page;

Then, you can access any property from your current page.

Hope this helps,

Marija

#131347
Jul 21, 2015 16:30
Vote:
 

Hi Marija,

That was exactly what I needed, thank you very much,

Mark

#131350
Jul 21, 2015 17:14
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.