Users can read intro but not message body

Author Message

James Ward

Tuesday 29 April 2003 12:13:31 pm

I wish to setup a site where anonymous users can see all the article titles and their intros but can not view the article body until they are logged in. I am switching from ez2.2.x to ez3 to attempt this.

I understand how to allow or deny users access to various classes but I see no way to seperate access to intros from access to the article bodies. Any help would be much appreciated.

working at www.wardnet.com
blogging at www.jamesward.ca

Paul Borgermans

Thursday 01 May 2003 1:38:07 am

There is no built in access control (roles) for attributes, but you may achieve this in the templates.

If you want this for all articles, edit (or create) an override template for your article template for full views. In this you make use of the fetch function for obtaining user info and act accordingly, for example in the demo setup, change :

{attribute_view_gui attribute=$content_version.data_map.body}

to

{let thisuser=fetch('user','current_user')}
{section show=$thisuser.is_logged_in}
{attribute_view_gui attribute=$content_version.data_map.body}
{section-else}
You need to <a href={'/user/login'|ezurl}>login</a> to see this sexy body
{/section}
{/let}

If you have a mix of public and semi-private articles, then copy the article class to a new one and use the override templates for this new class as shown above.

hth

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

James Ward

Thursday 01 May 2003 8:05:50 pm

Works like a charm Paul. This is a great feature for sites which will want to charge for access to some but not all of their content.

Many thanks,
James

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Thursday 01 May 2003 9:07:45 pm

I would like to add the actual login form to the
{section-else}

{/section}
portion of the example given by Paul. It's always nice to save our users an extra click where possible. :)

Anyone know where I can find the code to open the login form? It's not a class and it's not a section so I'm a little lost. Thanks for any help.

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Thursday 01 May 2003 9:34:40 pm

I seem to have figured it out. The following appears to work:

{section-else}
You need to login to see the body of this document.<br />
{include uri="design:user/login.tpl"}
{/section}

Obviously the key being the {include uri="design:user/login.tpl"} line.

It's amazing what you can do once you understand how this templating engine works. :)
Thanks for all your help.

working at www.wardnet.com
blogging at www.jamesward.ca

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.