1. There are a few ways. Either use GetDescendents on content loader or your way or using search engine like find. For small sites it doesn't matter much as long as you cache result. On larger sites, Find will work best...model usages as shared second best.
2. Use the classes below Episerver.Filters like
new FilterPublished().Filter(blocksToFilter);
Thanks Daniel,
but i found other threads with similar probelms as mine like this:
http://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2015/6/get-all-instances-of-a-certain-block-type-in-episerver-8/
As most of the repo's epi provides are already cached i'm not concerned about the performance...
Thanks for your insight as well...
As long as you have small to medium sites it will not be a problem. Might be worth making it possible to log the execution time with log4net though to be sure.
ListContentOfContentType is not cached btw so will always result in a database call.
I would still say it's the best way if you don't have Episerver Find. But since it will make a database call every time it will be fairly slow and will benefit from caching...
You are right though that ContentRepository calls are usually cached (like GetChildren etc). So caching that a second time will usually be a waste of typing... :)
Hi Guys,
i'm fetching all blocks in my cms (across all pages) like so:
Then i loop through all my usages and fetch the block type (CreationBlock) which are speciallike so:
However in my Result i have now published and unpublished blocks...
First: is the modelUsages repo thing the best way to fetch all blocks from the episerver database of contenttype CreationBlock?
Second: and if so, how can i then filter only the published ones?
Thanks in advance!!