Render block name

Vote:
 

Hi,


Is there a nice way to render a block name? I've tried most combinations like:

<%= CurrentBlock["Name"] %>
<%= CurrentBlock["BlockName"] %>
<%= CurrentBlock["ContentName"] %>

The only way that seems to work is:

<%= CurrentBlock.Property[0] %>

    

#77037
Nov 06, 2013 23:00
Vote:
 

maybe not so nice, but you could do this:

((IContent)currentBlock).Name

    

#77039
Nov 07, 2013 7:45
Vote:
 

Well, better than my approach. Thanks,


Shouldn't Name be a property on BlockData?

#77090
Nov 07, 2013 22:29
Vote:
 

The reason Name is not a property on BlockData is that Name is part of interface IContent. Blocks are a special building block which can both be used as properties on pages (often referred to as local blocks) in that case the block will not implement IContent. However blocks can also be created as own entititys (often referred to as shared blocks), in that case at runtime a subclass to the block type is created, this new subclass will implement IContent (and hence a shared block instance have a Name while a local block doesn't). More info is here http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/11/Shared-blocks--IContent/

#77101
Nov 08, 2013 11:48
Vote:
 

Thanks for the update Johan. Makes sense!

#77115
Nov 08, 2013 18:50
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.