You are here: Home / Documentation / How To's / How to customize a view in Plone 4

How to customize a view in Plone 4

by ledwell published Mar 13, 2013 01:35 PM, last modified Aug 16, 2016 10:50 AM
Customize a view template to not display sections like the "description".

If your trying to hide parts of template like the description or title. Plone 4 makes this somewhat more difficult for the non code savy. So I bugged Nathan VanGheem again and got a solution. Its easy to do but finding this online has been less than easy for people of my brain capacity. So here my attempt to fix that.

Lets say that you want your users to be able to choose from the "display" drop down menu whether or not they want to show the "Description" on a page. I mean I want to keep the description and its contents but I just dont want to show it on a certain page. Do the following;

Make a duplicate of the page template

  • login
  • browse to the zmi  (http://plonesite.blah/manage)
  • select "portal_skins" - "plone_content" -"document_view"
  • customize that view by choose the "customize" button (this should place the duplicate and you in the the custom folder).

Change the name of the template

Unless your trying to change every document thats using that view (in this case any "page") you'll want to change the name of this document then register that with the document (page) portal_type.

  • make sure you on in the custom folder by choosing "custom" in the zmi breadcrumb trail
  • select the checkbox next to "document_view"
  • choose the "rename" button
  • rename the template "document_view_body_only" 
  • choose save

Add in the code to remove the "description" field

  • select the text for the newly renamed document "document_view_body_only", this should put you into "edit" mode
  • copy the following code
<metal:content-description fill-slot="content-description">
    <metal:block define-macro="content-description">
    <!-- nothing -->
  • paste this code above this 
<metal:content-core fill-slot="content-core">
  • so in in context your code should look like
<metal:content-description fill-slot="content-description">
    <metal:block define-macro="content-description">
    <!-- nothing -->
<metal:content-core fill-slot="content-core">
    <metal:content-core define-macro="content-core">
        <metal:field use-macro="python:context.widget('text', mode='view')">
            Body text
  • save (of course) :)

Allow your users can choose the new view

  • while in the ZMI choose "portal_types"
  • choose Document (Page)
  • add the name of your new view to the "Available view methods", so add "document_view_body_only" along with the one thats currently there.
  • save changes
  • test

This is all you have to do. If you wanted to have something different than the name of the view appear in the "Display" drop down then then just make sure that when you have the "document_view_body_only" open in the zmi give that view a "Title". What ever you put there will appear in the "Display" drop down menu.

You can of course extend this sort of thing to the news items or event or what ever by following the pattern above.

Expanding on this

There are a variety of items that can be modified in this way ex. "title". You can find most of them in the zmi under "portal-skins" - "plone_templates" - "main_template".