Custom template for collection

227 views Asked by At

I'd like to create a page template that lists all of a particular content type where a certain value is true.

I assume the best way to do this is to make a custom page template for a collection.

So I follow these instructions here: http://www.uwosh.edu/ploneprojects/docs/how-tos/a-minimalist-view-for-collections

But I get an error "Macro expansion failed" as described here: Page template Macro expansion failed

However the answer there doesn't make sense to me. I'm not sure where to define that macros, is it in the type's .py file?

Does the combination of these two links describe the whole process or is the more to it? I the process described in full anywhere else?

OR am I thinking about this the wrong way, should I not be using a collection, just a new view for the content type that does the sorting itself?

1

There are 1 answers

2
Travv15 On BEST ANSWER

You're getting that error message right after you paste the tutorial's example code into portal_skins/custom/collection_minimal_view, right?

Screenshot of error message

That's because Zope is trying to anticipate what you're doing, but it doesn't know what the variable 'context' is going to be and it can't be sure 'context' will have a 'standard_view' attribute.

At any rate, if you ignore the error message, and follow the rest of the tutorial the new view does in fact work.

However, it isn't best practice to keep long term customizations in the custom folder, or really portal_skins, for that matter. A better approach would be to put the template in a package and register in your ZCML with:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:zcml="http://namespaces.zope.org/zcml"
    i18n_domain="plone">

    <browser:page
        name="minimal_view"
        permission="zope2.View"
        for="plone.app.collection.interfaces.ICollection"
        template="collection_minimal_view.pt"
        />

    <browser:menuItems
        for="plone.app.collection.interfaces.ICollection"
        menu="plone_displayviews">
      <browser:menuItem
          title="Minimal view"
          action="minimal_view"
          />
    </browser:menuItems>

</configure>