2

Is it possible to retrieve pages that uses a shared block instance in EPIserver 7.

Zaint
  • 59
  • 6

1 Answers1

3

You can use ContentSoftLinkRepository to get references to/from the content item. Let's say blockLink is the content reference of your block.

// resolving the repository. It can also be injected as a property or in your constructor.
var linkRepository = ServiceLocator.Current.GetInstance<ContentSoftLinkRepository>();

// loading soft links for your block
var referencingContentLinks = linkRepository.Load(blockLink, true).Where(link =>
                    link.SoftLinkType == ReferenceType.PageLinkReference &&
                    !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
                .Select(link => link.OwnerContentLink)
                .ToList();

Now you have the list of content links of pages/blocks/... that uses/references your block.

Petr Felzmann
  • 1,271
  • 4
  • 19
  • 39
Dmytro Duk
  • 184
  • 2
  • How would that work for blocks? I.e. if I need a list of blocks referencing a given block. There is no `BlockLinkReference` or similar in `ReferenceType` enum... – Azimuth Feb 05 '18 at 10:16