Path

ez.no / ezpublish / documentation / customization / tips & tricks / hiding attribute content


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

"this article" link doesn't work

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

01/05/2003
11:22:07 am
by Paul Borgermans

Last updated

04/07/2003
3:52:06 pm
by Bård Farstad

Authors

Paul Borgermans
James Ward
Ferdinando Orza
Bård Farstad



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.