Trying to prevent certain user roles from not adding or editing pages on specific templates. Any ideas what I am doing wrong? I get a really weird and long php error.
<?php if( $user = $site->user() and $user->hasRole('creative') && !$page->template() == 'default' ) { ?>
<?php // hide and show add edit here based on user role and template ?>
<?php } ?>
Thanks but not what i wanted… this ends up hiding the page all together from the panel. I just need to remove the abilty to add or edit pages in certain templates.
Wrap the buttons in the subpages.php in a similar if statement as above. The issue above was your code, so the same principle applies. You were declaring your $user variable inside your if statement. Notice the examples I’ve shared declare it before starting the if statement. Also $site didn’t seem to exist, so I used site(). You could also use $site = site(); $user = $site->user(); if you wanted it available on the page for other reasons.
The example they provided is meant to be used in templates, where $user and $site are already made available by Kirby. So it is checking if $user is equal to $site->user() and if it’s role is “editor”.
Within the snippet in question though, those variables weren’t declared. So declaring them rather than double checking that they’re declared was the solution.
For example. What do I need to put where when I want one template to load for a specific user role. I am still learning PHP so please forgive me for the newbie questions.
@cirstenkot, do you want certain pages of your site to only be visible if a user is logged in and has a certain role?
If so, click here for more information on restricting content/templates by user roles
There’s a lot of other information about the authentication system there as well, such as how to handle user log ins from within the site itself (not the panel), creating custom roles, etc.
This subject was more about modifying the panel, which from the sounds of it wasn’t what you really need. If I’m wrong about that let me know and perhaps you could explain exactly what you’re trying to achieve.
What I need. For a newbie php developer it is a big big big dream (Ok I will stop using emoticons…)
I want a client to register --> role is client --> I want the clients to add content, the best way is that the clients only will have one certain blueprint / template. --> user (best scenario) is not able to see content from other users even if they have the same role.
I believe this is definitely possible, but it would involve some development effort on your part. I’ve wrote a frontend registration/login/authentication/profile/etc setup for Kirby 1 a long time ago, but it utilized MySQL and didn’t integrate with the panel.
To summarize…
User visits …/registration page, fills out form. This is a front end template. Form utilizes Kirby’s $users->create() to create user using form inputs and set custom role w/o panel access. See the authentication docs from my last post for info on creating custom roles.
User visits …/login page, logs in. Redirects to …/create-content page. Again, both front end templates.
The “create-content” page has whatever form fields necessary to create your page. Form inputs feed into $pages->create() to create the page from the front end.
Doing it this way means you don’t have to modify the core panel files at all as well.
My code belongs to a corporation and is in a private repository. It wouldn’t be of much help here anyway. 1) It’s outdated Kirby 1 code. 2) it uses mysql databases and doesn’t tie in with the panel/kirby user setup. 3) it doesn’t use either the $users->create() or $pages->create() features available in Kirby 2. It actually doesn’t create pages at all… It only manages user profile information, test results, certification status, etc by communicating with MySQL.
ok wel I will give it a try just bij using the Kirby 2 code. If I manage to come up with something I will let you know! Thnx again for the workflow! It is a way to to start.