November Happy Hour will be moved to Thursday December 5th.

How to access the category property in a block?

Vote:
 

Hi!

We're having problems accessing the built in Category property in a block. If we get a default instance of a block and quickwatch it when debugging, we can see that the Category property is there, reached by ((Castle.Proxies.MyBlockProxy) (CurrentBlock)).Category. But how can we reach the categorylist by our CurrentBlock and be able to use its values? Or isn't this built in category property supposed to be used in a block?

Best regards,

Timea

#63997
Dec 06, 2012 14:34
Vote:
 

you need cast it to 

ICategorizable

see http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/11/Shared-blocks--IContent/

#63998
Dec 06, 2012 14:39
Vote:
 

And how easy it is when you know the answer. Thanks a lot :)

#63999
Dec 06, 2012 14:47
Vote:
 

For those who are still confused, this is how I finally got it to work:

((EPiServer.Core.ICategorizable)CurrentBlock).Category

which returns a CategoryList object.

#71644
Edited, May 24, 2013 22:33
Vote:
 

How do you set category programmatically cuz ((EPiServer.Core.ICategorizable)CurrentBlock).Category is just a get not set.

#116815
Feb 05, 2015 12:32
Vote:
 

You can set the Category by casting your block as an ICategorizable object, and then adding the category ID.

((EPiServer.Core.ICategorizable)<block>).Category.Add(<category id>);

#181470
Aug 21, 2017 16:35
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.