2

In code, how can I access the current Page Design my Page is using?

Tried to find something in the RenderingReference no luck.

1 Answer 1

3

That is quite simple, you need to use PresentationContext service. Here is an example:

ServiceLocator.ServiceProvider.GetService<IPresentationContext>().GetDesignItem(CONTEXT_ITEM);

It will do all the work your you:

  1. check if there is design selected on your page
  2. check design rules
  3. and at the end check Template to Design Mapping field (if design won't be resolved from above ones)

You can also inject PresentationContext using constructor injection like this:

public class MyClass
{
    protected readonly IPresentationContext PresentationContext;

    public MyClass(IPresentationContext presentationContext)
    {
        PresentationContext = presentationContext;
    }
}
1
  • Works like a charm thank you. Is this somewhere documented? These GetService() is new for me, I have seen in the showconfig.aspx that there are a lot more of these ServiceTypes, just wondering what each of them is able to provide.
    – Bgl86
    Commented Aug 24, 2019 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.