Showing a webpart only on the backend/cms site

Anthony Berube asked on August 2, 2021 17:01

Our company website has 3 versions (dev,staging,prod). I'm trying to make a webpart repeater only appear on the Prod one and in the backend (so when the path is websiteName.com/Admin/cmsadministration...)

The difference with all the version is only the start of the path dev.webName.com staging.webName.com webName.com

I've tried to do ViewMode != "LiveSite" but I guess the production backend counts as the LiveSite so the webpart doesn't show.

Is there a macro or something that can help me get the backend path or to know if we are in an edition/cms mode (Admin/administraion...)

Correct Answer

Brenden Kehren answered on August 3, 2021 15:46

You can use a macro in the Visibility property of the web part. Something like below should work:

PortalContext.ViewMode != "LiveSite" && domain.ToLower().Contains("yourdomain.com")

1 votesVote for this answer Unmark Correct answer

Recent Answers


Liam Goldfinch answered on August 2, 2021 18:43

I would probably recommend you use a custom macro, then you can add your own logic to decide if the webpart should show or not.

See the documentation here.

You could have an AppSetting in the web.config to dictate which environment the site is running on, and your custom macro could check this is set to prod.

1 votesVote for this answer Mark as a Correct answer

Anthony Berube answered on August 2, 2021 19:48

The problem is that I'm completly new with cms/k#/kentico and I have no idea what is everything.

So i was trying to get an easy solution where I can just do something from the webpart itself (like if I didn't had access the the code or custom stuff). A macro that already exist that gets the path of your browser or that knows if you are in administration mode or not.

If there's really no other easy solution, I'll have lot of work to learn haha

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on August 2, 2021 20:23

If you're only wanting the webpart to appear in the backend and not the frontend, you can use the ViewMode macro like this:

{% PortalContext.ViewMode == "Edit" #%}

If you're wanting to show the webpart based on different environments (e.g. for production) then you could utilise the machine name macro (assuming they are on different machines):

{% SystemContext.MachineName == "PRODUCTION" %}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.