Forum

Thread tagged as: Question, Forum

Webpage Development Mode

Hi all,

Does anyone know of a way that I could modify Perch to show a checkbox next to each page that I could check when undergoing development on that page? Ideally, I would like to implement this on all pages so that when that part of the website is undergoing development, website visitors would be redirected to a page that says "That page is undergoing maintenance at the moment"...

Any suggestions greatly appreciated.

Conor Harkins

Conor Harkins 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Conor,

If the page has never been live, it's probably better you don't publish it until you've completed development in a local environment.

Anyway, a possible solution for this would be to use page attributes. The following adds a checkbox to the Details tab of the page in the control panel.

templates/pages/attributes/default.html:

<perch:template path="seo" />
<perch:template path="dev" />

templates/pages/attributes/dev.html:

<perch:pages id="dev_mode" type="checkbox" label="Development Mode" suppress="true" divider-before="Development"/>

page.php:

$dev_mode = perch_page_attribute('dev_mode', [
    'template' => 'dev.html'
], true);

if($dev_mode) {
    PerchSystem::redirect('https://example.com/');
}

Thanks Hussein! I’ll try that tonight.

Hussein... your solution... it just works...

It's brilliant, thank you!

Conor Harkins said:

Hussein... your solution... it just works...

It's brilliant, thank you!

Yes Hussein, your reply inspires a few thought for me, and I think that’s a good solution you suggest.

While I do no live development since I have a dev setup on my local machine, your response could be used to limit access while under live development.

I added the final piece of code to the Perch runtime - is this ok? Or will this get overwritten in an update?

It just means that I don't have to go through every single page and add the snippet.

The only problem I am now faced with is that I, myself, cannot see the page :') So I have no idea what it looks like while I am developing it - this may take more thought - as you were.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Oh right! I believe you can check whether you are logged into Perch as Drew mentions here.

So combine that with what we have:

$Users = new PerchUsers;
$CurrentUser = $Users->get_current_user();

if($dev_mode && (!is_object($CurrentUser) || !$CurrentUser->logged_in())) {
    PerchSystem::redirect('https://example.com/');
}
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Please do not change core Perch code. If you do so we can no longer offer support.

Runway includes a site behind login mode as a feature that allows you to put the site in development so it can only be seen by people logged in with an admin account.

Please do not change core Perch code. If you do so we can no longer offer support.

Hi Rachel. I am not changing the core code, it would only be the runtime inside perch (not core) - does this still count? I noticed this file was only including the core runtime code so thought this would be ok.

And thanks again, Hussein.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you want to add code into the runtime chain then you can do it with an app.