Jump to content

Using wireframe only for logged in users?


Mats
 Share

Recommended Posts

Sure. In your template file (or auto append file, here for _main.php), just include the correct template according to the user's login status.

<?php namespace ProcessWire;

if($user->isGuest())
  include('_main_regular.php');
else
  include('_main_wireframe.php');

 

  • Like 1
Link to comment
Share on other sites

@BitPoet I tested your solution and i'm probably missing something but it's not working. 

I tried this after searching the API docs:

Quote

 

<?php namespace ProcessWire;

if($page->editable()){
    $page->template->altFilename = "wireframe";
}

?>

 

And it seems to work.

Sets the file but doesn't change it once it's set. 

Link to comment
Share on other sites

A lot depends on the exact structure of the site (e.g. if you use automatic append of a generic template file) and at what point you introduce your code. If you're already inside a template's php code, changes to altFilename won't do anything. You'd have to do that before rendering of the page has started, e.g. through a hook in site/ready.php:

<?php namespace ProcessWire;
/*
wire()->addHookBefore('Page::render', function(HookEvent $event) {

	$page = $event->object;

	if($page->template->name == 'your-template-you-want-to-change' && $page->editable()) {

		$page->template->altFilename = 'wireframe.php';

	}

}
*/

Actually, I should have given that code a test spin before posting. The correct hook would be to ProcessPageView::execute.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...