How to make a class partially visible?

Author Message

Marko 1473

Thursday 23 September 2004 2:29:14 am

I'm quite new to eZ publish (and I like it) and this is my first post here. :-)

What is the best way to make a class partially visible to anonymous users?

I have a list of articles (with name, intro, body and image as attributes) which are all in a folder (section) called newsletter. This section is visible only by subscribers.

However, I need to create a page with all article titles and introductions which should be visible to everybody. So, only one part of the article class (title, intro, image) is available to everybody, but when they click 'read more', they should be able to see the full article only if they are subscribed to the service.

What's the best way to do that? Has anybody had any experience with a similar issue?

Kind regards,
Marko

Nicolas Heiringhoff

Thursday 23 September 2004 3:18:15 am

Hello Marko,

you can create a new folder in your menu, called "everybody" for example". Now create an override, for that folder, where you just fetch the desired attributes of your article class in the "newsletter" folder:


{* The value 130 in this fetch must be the node number of the folder "newsletter" where all your articles are stored, 130 is just an example*}

{let node=fetch( 'content', 'node', hash( 'node_id', 130 ) )}
    
<h2>{attribute_view_gui attribute=$node.object.data_map.title}</h2>
<br />

{attribute_view_gui attribute=$node.object.data_map.intro}

<br />
{attribute_view_gui alignment=right image_class=small attribute=$node.object.data_map.image.content.data_map.image href=$node.url_alias|ezurl}
 {/section}

{/let}

<br />

<a href={"/login"|ezurl} border="0">read more...</a>

You must create another Folder called "login" for example, where you do the login.
After the user has logged in corectly, you can redirect him to the original "newsletter" folder, where you show all the content

Nico

http://www.heiringhoff.de

Marko 1473

Friday 24 September 2004 6:04:23 am

Nico, thanks for your reply.

I've just tried what you suggested but no luck.

When I put, as you suggested (node 91 is a folder which contains all the
newsletter articles):

{let node=fetch( 'content', 'node', hash( 'node_id', 91 ) )}
<h2>{attribute_view_gui attribute=$node.object.data_map.title}</h2>
<br />

it gives me nothing. :-( I slightly modified the code above into:

{let article_list = fetch( 'content', 'list', hash( 'parent_node_id', 91 ) )  }
    {section var=article loop=$article_list}
      <h2>{attribute_view_gui attribute=$article.object.data_map.title}</h2>
    {/section}
{/let}

and that gives me the list of article titles. To be honest, I don't know why the first
example won't work - still a lot to learn about eZpublish.

Does $node.object.data_map.title which you suggested refer to a title of every single
article, or that's the title of the folder containing articles?

Anyway, all the examples above were done as admin, i.e. no viewing restrictions.
If I try to do it as a guest, I see no article titles at all. All the articles
reside in newsletter folder/newsletter section which is visible only to
subscribers. So, I suppose the result (nothing) is expected as guests don't
have viewing permissions of the articles. Am I wrong here?

I'm not completely sure what you have in mind. Should I have this structure
with newsletter folder/section and articles in it? Should it be restricted
only to privileged users (subscribers, admins, editors, but not to
guests, anonymous users)?

So, I'm still not there. :-(

Thanks in advance.
Marko

Nicolas Heiringhoff

Friday 24 September 2004 6:44:49 am

Hi Marko,

I think there are different solutions to the problem.

Try the following code in the override of the "folder for everybody"


{* Fetch everything that is under node #91 (children, grand-children, etc.) *}
{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 91, 'sort_by', array( 'published', false() )) ) }

{* Loop through the nodes and display their names. *}
{section loop=$nodes}

{$:item.data_map.title.data_text}
<br />
{$:item.data_map.intro.data_text}
<br />
<img src="{$:item.data_map.image.content[small].full_path}">



 {/section}

{/let}



this should get you the titles, intros and the images of all the articles in node 91.
If not, than the there is a restriction interference.

Tell me, if the code above does work for you.

I am sorry, I suggested the prior code.

with


{let node=fetch( 'content', 'node', hash( 'node_id', 91 ) )}
<h2>{attribute_view_gui attribute=$node.object.data_map.title}</h2>
<br />

you just fetch one node, not the content of the node.

Nico

http://www.heiringhoff.de

Marko 1473

Friday 24 September 2004 8:08:44 am

Hi Nico,

Yes, the latest code you sent gets the titles, etc. of all articles in node 91.
And it works fine for Administrators, Editors and Subscribers.

However, it fails to work for Guests/Anonymous users. Guests have read access
to all standard section content:
content - read - Section(Standard section), but there is no such entry for
Newsletter section. I suspect it fails because of that.

And that's exactly what I'm looking for. I want all users to see all of the
article titles, images and introductions. But, the full article is viewable
only to subscribers.

I probably didn't explain it properly, but I hope it is clearer now.

How could I make that happen?

Thanks,
M.

Lazaro Ferreira

Friday 24 September 2004 10:11:38 am

Hi,

if I understood right, what you want can be done programming the view/full template of your article class, you can put code there to only show the information if the user belongs to the subscriber group, on the other hand you have the view/line template that can show title, intro, etc to everybody

You will need to override your view/full template for article class objects in section newsletter, it should do the trick

Here you have the link on how to know the main group of the current user :

http://ez.no/ez_publish/documentation/customization/custom_design/template_variables_set_by_ezpublish

Lazaro

Lazaro
http://www.mzbusiness.com

Marko 1473

Saturday 25 September 2004 6:16:45 am

Thanks Lazaro, you are a star. That's exactly what I was looking for.

I've allowed everybody to see newsletter section, but when it comes
to show the article, we have a two different outputs - one for
subscribers/editors/admins and one for guest/anonymous users.

I've created override for view/full for article class object with
something like:

{let
    current_user=fetch('user','current_user')
    group_id=$current_user.contentobject.main_parent_node_id
}

{* Test for the group_id - 44 (anonymous) or 12 (guest) *}
{section show= or( $group_id|eq(12), $group_id|eq(44) ) }
    {attribute_view_gui attribute=$node.object.data_map.title}
    {attribute_view_gui attribute=$node.object.data_map.intro}
    {attribute_view_gui attribute=$node.object.data_map.image image_class=medium}
    <p>Login to see the rest of the article!</p>
{section-else}
    {attribute_view_gui attribute=$node.object.data_map.title}
    {attribute_view_gui attribute=$node.object.data_map.intro}
    {attribute_view_gui attribute=$node.object.data_map.image image_class=medium}
    {attribute_view_gui attribute=$node.object.data_map.body}
{/section}

Nico, Lazaro - thanks again for your input.

Marko

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