Doesn't Johans loading multiple instaces work?
IEnumerable<ContentReference> references = GetSomeReferences(); IEnumerable<IContent> items = Locate.ContentRepository().GetItems<IContent>(references, LanguageSelector.AutoDetect());
Here is a code example if you mean looking for the content of certain type:
var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>(); // loading a block type var blockType = contentTypeRepository.Load<YourBlockType>(); // getting the list of block type usages, each usage object has properties ContentLink, LanguageBranch and Name var usages = contentModelUsage.ListContentOfContentType(blockType); // TODO: do the stuff with usages
Thank for the answers!
This will get me each usage of the created block, but i would like to get
a list of the available shared blocks no matter on which paghe the block is used.
For example, when im using contactblocks i would like to make a list of all
published contactblocks and get the information from the blocks that i will then use
to present on another page. Also, is it possible to somehow cast a contentusage to its actual blocktype
or do i have to get that content by using the contentreference ID from the contentusage object.
Thanks in advanced!
usage.ContentLink is the reference to block instance, so I guess this is what you need.
I will borrow this thread.
If I iterate on the usages in Dmytros example I thought I would get only the published instances of my block type. But it seems that I get all versions.
In my case I populate a dropdown in an selectionfactory (I use the contentlink as value in my dropdown.). In another block where I use the dropdown I would like to choose the current version of a specific block instance for getting som data.
But now every time I publish my block containing the data I want to use I get another version in the dropdown. And to get the latest version in my "consuming" block I need to go into forms mode an choose the latest version which I don't want to do.
In my consuming block I want to choose among blocks of my blocktype by name and be able to always load the latest version.
How can I accomplish what I want.
I solved it. On the usage you can do like this ContentLink.CreateReferenceWithoutVersion() to get the correct reference.
Thanks Per. However
is obselete. Use this instead
I am having some problems with the block types and wondering if anyone
have any solution for getting all the instances of a blocktype?