Open hidden article as logged in admin

Hello

what is the best case to achieve the following:
I want to set some pages as hidden as i am writing the content, but i want to display a preview.
I dont want to use the preview Plugin i found here, as i am using 100% width of the browser and i need to see how the choosen page reacts.

So, how do i get the current logged in Panel User and check if he is an admin?

If the clause is fault i could redirect to the 404 Page.

Thank you!

A simple if statement:

if(($user = $site->user()) && $user->isAdmin()):
  // show page
else:
  // bye-bye
endif;
1 Like

Thank you.
Is what i plan “best case” or something else like a kirby standard?

That’s perfectly fine. If you don’t want these pages to be permanently hidden, you might use a field in your page instead to check if the page is published or not and react on that, so that later you don’t have to change the template but only the field value. Depends on your use case.

1 Like

Okay, i will implement that code now.

Thank you, like always :wink:

Why does this not work for me?
I do as Sonja suggests, but the code in the if statement is executed (and content shown) whether I am logged in or not.
What am I not getting?

What is your code and Kirby version? This thread is about Kirby 2.

I am on 3.7.1.
Sorry, wasn’t aware, this would not apply after Kirby 2.
My code is:

<?php if(($user = $site->user()) && $user->isAdmin()): ?>
  <section class="updates-container">
    <h2>Updates</h2>
    <?php $items = $article->updates()->toStructure();
    foreach ($items as $item):
      …
    endforeach;
    ?>
  </section>
<?php endif ?>

A user in Kirby 3 is no longer a site user but a $kirby->user()

Au-kay. Works beautifully.
Thank you so much for you swift support. :rocket: :pray: