ez.no / ezpublish / documentation / customization / tips & tricks / hiding attribute content
These documentation pages are no longer maintained. Please visit the new documentation site.
The role system (permission system) currently does not have support for attributes. But for some simple situations, quite a lot can be done in the templates by fetching the current user object and use the show action in
{section show= ...}{/section}
The following code sample hides the body text of an article in the full view (for example to use in full_class_2.tpl in the demo setup) for non-logged in users.
{let thisuser=fetch('user','current_user')} {section show=$thisuser.is_logged_in} {attribute_view_gui attribute=$content_version.data_map.body} {section-else} <h2> You need to <a href={'/user/login'|ezurl}>login</a> to see this sexy body</h2> {/section} {/let}
This can be extended of course to more complex situations. For example you can access the groups the current user object belongs and get group based access to attributes. The same applies to roles which are also in the user object. To see the available information on the current user object, dump the variables as shown in this article
If you want to restrict access to some but not all of your Articles try the following:
Edit the Article class and add a checkbox with an identifier like restrict_access.
Then in your full_class_2.tpl file replace the line:
{attribute_view_gui attribute=$content_version.data_map.body}
with:
{section show=eq($node.object.data_map.restrict_access.data_int,1)} {let thisuser=fetch('user','current_user')} {section show=$thisuser.is_logged_in} {attribute_view_gui attribute=$content_version.data_map.body} {section-else} {include uri="design:user/login.tpl"} {/section} {/let} {section-else} {attribute_view_gui attribute=$content_version.data_map.body} {/section}
Note: I also immediatly prompt the user for the username and password with {include uri="design:user/login.tpl"} to save them an extra mouse click.
Now when you want to restrict access to your articles all you need to to is click the restrict_access checkbox when you create a new article.
Comments
broken link
Joanie Chembars
Wednesday 12 January 2005 7:10:13 pm