Mats Posted December 14, 2022 Posted December 14, 2022 Hello! Is it possible to use wireframe only for logged in users and guest users are presented with the regular template?
BitPoet Posted December 14, 2022 Posted December 14, 2022 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'); 1
Mats Posted December 14, 2022 Author Posted December 14, 2022 @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.
BitPoet Posted December 14, 2022 Posted December 14, 2022 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.
BitPoet Posted December 14, 2022 Posted December 14, 2022 For what it's worth, it makes sense to have the capability to test drive new template files, so I rolled a little module. This adds a field to the template configuration for an alternative template file only used for editors. https://github.com/BitPoet/TemplateTester 4
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now