Jump to content

Is there way to get information about current user in templates?


apeisa
 Share

Recommended Posts

Is there any way to see information like:

a) is the current user logged in or guest

b) which roles he/she has

c) what is the username of current user

There is $session variable, but I couldn't find that information from there.

It would be great if we would have global variable $user.

Link to comment
Share on other sites

And the docs are already there, big thanks Ryan! I am building a small "admin bar" to take further the idea of "EDIT" link. I hope it turns out something useful. If not, I hope I learn something useful :)

It sounds useful! I'm looking forward to seeing what you come up with. Note that there are still more API variables I have to cover in the docs:

$users

$config

$roles & Role

$permissions & an individual Permission

$fieldgroups & an individual Fieldgroup

$templates & an individual Template

PageArray

I've held off on $roles, $fieldgroups and $templates because I want to tie fieldgroups and templates together like they are on the admin CP (currently they are separate on the back end).

For roles, I'm planning to make them assigned to templates rather than pages (as the default option), so waiting to finish that before finishing that part of the documentation.

Link to comment
Share on other sites

I have something simply to show if you guys are interested in this. Very simple stuff, three files:

adminbar.inc
adminbar.css
adminbar.js

[removed broken screenshots]

There was already this modal variable on admin theme that stripped all the unnecessary stuff out, so I think something like this have been in thoughts before? Only bad thing is that after "Save Page" the modal state doesn't stay and it shows the navigation.

I will keep improving this and it would be great to hear some comments & ideas.

Link to comment
Share on other sites

This looks awesome, thanks for your work with this! Are you interested in bundling either of these as a module for other people to use? Let me know and I can add a modules section to the download page,  as well as assist with any help you need making it a module or adding hooks, etc.

I agree re: drupal7 modal, it was a great improvement.

The modal var in PW2 is specific to things like the image editing popup and link selector popup (currently used with TinyMCE Fieldtype). It basically just turns off the branding (as you saw). Not sure that's what we would want in this case (?), but perhaps something similar with more minimal branding?

Thanks,

Ryan

Link to comment
Share on other sites

Great minds think alike!

You're making me sad [ :-[ :-\ :'(], because you just did what I was thinking about (customizable 'PW widget' for logged in users), although I don't like the modal part (but that's just me :))

But just as Ryan, I'd like to help to have it bult as module/plugin :) – [just as few posts above ;)]

Link to comment
Share on other sites

Thanks guys!

It would be great to see this to becoming a real module. I haven't looked modules at all yet, so I have no idea how to go with it. So any help/collaboration is appreciated. I have more ideas like creating a new page from adminbar and seeing what roles have access/edit rights for current page.

I also had wild idea of inline editing the fields (I found http://www.aloha-editor.org/ and got idea from there). So you could click "Edit page" and that puts small edit icons on top of each editable field. Then you click on fields and you could edit those right on the page. And after you have made changes there is big "Save" button that you need to click. It would be pretty nice way to edit & preview at the same time. What you guys think? Would it be better, good alternative or just not so great idea?

UI & JS side of things is something I could easily handle, but the I'm not so familiar with the API to say if this could be easily done? I see there some problems already: we need to tell in templates which fields are editable and what their field-name is. It probably makes template files (which are now very easy and flexible) a bit messier.

Link to comment
Share on other sites

It would be great to see this to becoming a real module. I haven't looked modules at all yet, so I have no idea how to go with it. So any help/collaboration is appreciated. I have more ideas like creating a new page from adminbar and seeing what roles have access/edit rights for current page.

I'll be happy to get you started with a "blank" module that you can build it on top of. What I recommend is that we hook into the Page::render method, grab it's output, and insert your js and css markup file links right before a page's closing </head> tag. That way, when someone installs the module, it'll just start working without them having to do anything on their own. Of course there will be those that want to control the placement of those things, so I'll show you how to make that configurable. The PHP code that is in your .inc will become the module code. Let me know if this sounds like a good plan to you, and I'll follow up with posts showing you how.

I also had wild idea of inline editing the fields (I found http://www.aloha-editor.org/ and got idea from there). So you could click "Edit page" and that puts small edit icons on top of each editable field. Then you click on fields and you could edit those right on the page. And after you have made changes there is big "Save" button that you need to click. It would be pretty nice way to edit & preview at the same time. What you guys think? Would it be better, good alternative or just not so great idea?

There are definitely merits to inline editing, depending on the site. I view the needs of page viewing and page editing as fundamentally different, and prefer to have an interface that is designed for one or the other (though the 'overlay', like in Drupal, and in your example, is a nice compromise). But there are many cases where it is really handy to be able to edit inline, if the site design supports it. As an example, I like to make moderated comment approval inline, so that I can just click "approve" or "spam" while viewing the comments (though Akismet mostly does that for me now).  There are plenty of other cases, and I'm betting that Aloha Editor will provide some good opportunities.

I think you'll find ProcessWire works well when you want something to be editable inline. On the front end, you would just need to make sure that the page is editable before including the inline editors, i.e. if($page->editable()) { ... }. Then you'll need for your template, include or module to look for when they've clicked 'save', i.e.

<?php

if($input->post->submit_save && $page->editable()) {
    // turn off runtime formatters (like entities, markdown, date formats, etc). 
    $page->setOutputFormatting(false); 
    // go through all the submitted fields and set those that are applicable
    foreach($input->post as $field => $value) {
        if($page->fields->has($field)) $page->set($field, $value); 
    }
    // if the above resulted in a change, then save the page
    if($page->isChanged()) $page->save(); 
    // turn output formatting back on so it's in the proper state for viewing
    $page->setOutputFormatting(true); 
} 

Note that if the "save" button is just attached to individual fields, and you'll only be saving one field at a time (possibly ajax driven), then you may want to just save the field rather than the whole page, i.e.

$page->save('field name'); 
Link to comment
Share on other sites

Ryan: sounds like a plan to me. If you provide me blank module and details about right hooks, I will turn this into real module.

And I have to agree about inline editing. It could be difficult to understand that when you make changes inline it could show up in many different places, not just the one you are "inline editing". Current way is more like content management, not just editing a web page.

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...