Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Removing things from the portal view for anonymous visitors

by rossl — last modified Dec 30, 2008 03:02 PM
How to remove some features from the default "home page" view of your portal for anonymous visitors - but ensure they reappear once logged in.

You may wish to hide certain content in your site from users who are not logged in. There are three general strategies:

  • In portal_actions and other action provider, you can set a condition python: member. This shorthand will test whether the member object exists, which it only does for logged-in users. Use this to hide certain portal tabs or personal actions, for instance.
  • Modify the permissions in the root of the Plone site and in the relevant workflows under portal_workflow so that they do not permit the Anonymous role to view content. This allows you to restrict access to certain types of content and views (e.g. the folder listing view)
  • If neither of the above is feasible, it may be possible to customise certain page templates by adding tal:condition="not: here/portal_membership/isAnonymousUser" to the relevant tags. This will exclude the tag on which the statement is set if the current user is anonymous.

In particular, you may want to look into making adjustments to the following skin files, by customising them in the ZMI or in your own product.

  1. the searchbox /portal_skins/custom/global_searchbox
  2. the calendar /portal_skins/custom/portlet_calendar
  3. the news portlet /portal_skins/custom/portlet_news and
  4. the navigation portlet /portal_skins/custom/portlet_navigation

In the examples below, the above tal:condition is added to the first logical place in the local custom version of the skin or to the existing condition if there is one there already.

In /portal_skins/custom/portlet_navigation:

 <div metal:define-macro="portlet"
       i18n:domain="plone"
       tal:omit-tag=""
       tal:condition="not: here/portal_membership/isAnonymousUser"
       tal:define="isContainer here/isPrincipiaFolderish|nothing;
       ...>

In /portal_skins/custom/portlet_calendar:

 <div metal:define-macro="portlet"
     tal:omit-tag=""
     tal:define="DateTime python:modules['DateTime'].DateTime;
                 current python:DateTime();
                 yearmonth here/getYearAndMonthToDisplay;
                 year python:yearmonth[0];
                 month python:yearmonth[1];
                 prevMonthTime python:here.getPreviousMonth(month, year);
                 nextMonthTime python:here.getNextMonth(month, year);
                 weeks python:here.portal_calendar.getEventsForCalendar(month, year);
                 anchor_url request/anchor_url | here_url;
                 anchor_method request/anchor_method | template/getId;"
      tal:condition="not: here/portal_membership/isAnonymousUser">

In /portal_skins/custom/portlet_news:

  <!-- The news box -->
<div metal:define-macro="portlet"
     tal:define="results python:request.get('news',
                            here.portal_catalog.searchResults(portal_type='News Item',
                                                              sort_on='Date',
                                                              sort_order='reverse',
                                                              review_state='published')[:5]);"
     tal:condition="python:test(template.getId()!='news' and 
(not here.portal_membership.isAnonymousUser()) and results, 1, 0)">

and /portal_skins/custom/global_searchbox now starts with:

 <div id="portal-searchbox" metal:define-macro="quick_search" 
tal:condition="not: here/portal_membership/isAnonymousUser">

The same principle is of course applicable to other page templates as well.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.