How can I preview my pages before publishing them?

Next thing I tried is updating ModX to newest version 2.8.3, updating the Extra’s, disabling all Extra’s, all to no avail. Viewing unpublished resources gives a 404.
I can view unpublished resources in other ModX websites though.
So there must be some setting that blocks viewing them in this one.

I tried unsetting the view_unpublished setting for the manager role in a website where I cán view unpublished resources, flushed permissions, logged out and back in and…
I could still view unpublished resources. So I think the view_unpublished setting has nothing to do with it.

That doesn’t make sense!

Maybe you can run this snippet (uncached) on a page to check if you set the view_unpublished permission correctly.

if ($modx->hasPermission('view_unpublished')){
    return "User can view unpublished resources.";
} else {
    return "User CAN'T view unpublished resources!";

Are you on an installation with more than one front-end context by any chance? There is an issue with viewing unpublished resources in multiple context installs, even for sudo admins.


Indeed, I have four contexts: three language contexts to use with Babel and the web context.
But the other site where I cán view unpublished resources has those contexts as well.

It says “User can view unpublished resources” when I load a published page with the snippet.
An unpublished page gives 404 with no output of course.
The other website where everything works as expected outputs on both a published and an unpublished page: “User can view unpublished resources” (of course :slight_smile: just had to check.

On the correctly working website I tried unsetting ‘view_unpublished’ and… your snippet still outputs ‘User can view unpublished resources.’ when I view an unpublished page.

In comparing your working vs non-working sites, it will be important to test viewing unpublished resources from each context in each site. From my experience with a multi context installation, you can only view unpublished resources in the web context (or the context where you have logged in.)

This has to do with where the session has been set on login (I think), and there is a work-around I read somewhere but can’t now find. Hopefully someone can post that here… as I have been meaning to fix some sites…

1 Like

In a case like this, it’s sometimes helpful to try incognito or private mode in your browser to make sure that different visits are independent.


Welcome to the MODX Community. You’ll probably find things are different around here for people new to MODX. You’re not going to get attacked or insulted because you didn’t ask the question exactly right.


Yes, I need to find that as well. I have a few multi-context sites that I’ve tried unsuccessfully to enable a single login to access all of them at once.

Try setting the system setting “session_cookie_samesite” to “Lax”. That has helped with certain things on my sites. If your different contexts use different domains or subdomains, though, this may not help you.

1 Like

I always login to the manager, not specifically into a context. I don’t have different domains for the language contexts… they’re like… and… Am I missing something?
I’ll test with resources from all the different contexts though, thank you.

I have no setting ‘session_cookie_samesite’. I do have ‘session_cookie_domain’ though. After setting that one to ‘lax’ I couldn’t login to the manager anymore. Luckily this was in my dev copy :slight_smile: Schermafbeelding 2021-12-14 om 09.04.14

I believe the system setting ‘session_cookie_samesite’ was added in version 2.8.2. Maybe you are using an older version of MODx.

If you aren’t using different domains (or subdomains) for your different contexts, then I don’t think there should be a problem with the session.

Maybe try changing my snippet from above to this, to also test for the session state (as it is done in the code).

$output = '';

if ($modx->getSessionState() === modX::SESSION_STATE_INITIALIZED){
    $output .= "Session initialized.<br>";
} else {
    $output .= "Session NOT initialized! Session state is " . $modx->getSessionState() . "<br>";

if ($modx->hasPermission('view_unpublished')){
    $output .= "Can view unpublished";
} else {
    $output .= "CAN'T view unpublished!";
return $output;

I’m on version 2.8.3 and I searched the system settings for cookie which gives the screenshot of my previous message.
I will try the snippet you provided and return here later, thank you very much for answering.

With a published page, the snippet outputs:

Session NOT initialized! Session state is 2
Can view unpublished

An unpublished page is still a 404.

In another website where I can view unpublished resources, it outputs for both published and unpublished resources:

Session initialized.
Can view unpublished

So the unitialized session is most certainly the culprit.

Have to find out why the session isn’t initialized.

Maybe you can try adding the system setting session_cookie_samesite manually.

The value of 2 is SESSION_STATE_EXTERNAL (session is being controlled by an external provider), but I don’t know what that really means.

SESSION_STATE_EXTERNAL means that the session is being started before MODX is even executed, or at least before it tries to initialize the session.

Getting nearer :slight_smile: but a new riddle emerged.