Daniel
Daniel

Reputation: 1406

Plone: can I make @@manage-portlets use a template other than main_template.pt?

I have an alternate homepage template, homepage.pt, which has a different layout. When I click the manage-portlets link to edit the portlets, though, it uses main_template.pt instead of homepage.pt. Is there any way to have @@manage-portlets use whichever template the page you're editing the portlets for uses? It's workable as is, but the layout is quite different to what the page actually looks like.

Upvotes: 1

Views: 256

Answers (2)

Daniel
Daniel

Reputation: 1406

So, the answer is yes, with a little messing around. You can use an alternate template for manage-contextual.pt out of plone.app.portlets and change the metal:use-macro attribute to use your custom macro. I used jbot and naming the file:

plone.app.portlets.browser.templates.manage-contextual.pt

does what it should. This replaces the manage portlets view for all pages though, including ones that were using main_template.pt. Not insurmountable, but a little annoying. I can think of a few solutions:

  1. Just add a new manage-portlets-yourspecialtemplate view that has a copy of manage-contextual.pt, modified to suit. This is the easiest way and lets me edit all my portlets (including the ones that were already there) in context as I originally wanted. Yay!
  2. I didn't try it, but if the only page you have with a non-main_template.pt template is your homepage you could try registering a manage-portlets view for the Products.CMFPlone.interfaces.IPloneSiteRoot interface. I haven't tried adding views with the same name (but applying to different interfaces) so I have no idea if this works.
  3. Some conditional logic in manage-contextual.pt that uses a different template based on whatever you use to distinguish whichever pages have different templates.

Upvotes: 0

Franklin Kingma
Franklin Kingma

Reputation: 156

We register another page for this purpose and register an portal_actions object action

zcml:

<browser:page
    for="plone.portlets.interfaces.ILocalPortletAssignable"
    class="plone.app.portlets.browser.manage.ManageContextualPortlets"
    name="manage-homepageportlets"
    template="templates/managehomepageportlets.pt"
    permission="plone.app.portlets.ManagePortlets" />

view:

class HomepageView(BrowserView):
    template = ViewPageTemplateFile('templates/homepage_view.pt')

action:

<object name="homepage portlets" meta_type="CMF Action">
   <property name="title">Homepage-portlets</property>
   <property name="url_expr">string:${portal_url}/@@manage-homepageportlets</property>
   <property name="available_expr">python: here.absolute_url() == portal_url</property>
   <property name="visible">True</property>
</object>

template:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:metal="http://xml.zope.org/namespaces/metal"
  xmlns:tal="http://xml.zope.org/namespaces/tal"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  metal:use-macro="context/main_template/macros/master"
  i18n:domain="plone">

<body>
<div metal:fill-slot="main">
    <h1 class="documentFirstHeading">Manage Homepage Portlets</h1>
    <h2>Top portlets</h2>
    <span tal:replace="structure provider:project.homepagetop" />
    <h2>Middle portlets</h2>
    <span tal:replace="structure provider:project.homepagemiddle" />
    <h2>Bottom portlets</h2>
    <span tal:replace="structure provider:project.homepagebottom" />
</div>
</body>
</html>

Upvotes: 3

Related Questions