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.

eZ debug

Timing: Jan 30 2025 19:42:04
Script start
Timing: Jan 30 2025 19:42:04
Module start 'layout'
Timing: Jan 30 2025 19:42:04
Module start 'content'
Timing: Jan 30 2025 19:42:04
Module end 'content'
Timing: Jan 30 2025 19:42:04
Script end

Main resources:

Total runtime0.0276 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.2656151.2266
Module start 'layout' 0.00620.0053 739.4922220.7188
Module start 'content' 0.01160.0143 960.21091,001.8359
Module end 'content' 0.02580.0017 1,962.046937.9922
Script end 0.0275  2,000.0391 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003111.2801140.0002
Check MTime0.00124.5342140.0001
Mysql Total
Database connection0.00093.404110.0009
Mysqli_queries0.003111.316530.0010
Looping result0.00000.079610.0000
Template Total0.00124.510.0012
Template load0.00093.404110.0009
Template processing0.00031.031410.0003
Override
Cache load0.00072.370110.0007
General
dbfile0.00165.809780.0002
String conversion0.00000.040740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs