开发者

What's the most straightforward way to move the globalnav to the footer, only on the front page

开发者 https://www.devze.com 2023-04-01 21:31 出处:网络
I have hidden various elements of the normal Plone front page via: .section-front-page #portal-globalnav {

I have hidden various elements of the normal Plone front page via:

.section-front-page #portal-globalnav {
    display: none;
}

Now, I want to add a globalnav to the bottom near the footer. I've considered a variety of approaches:

  • A browser view/template selected via the Display menu
  • Another viewlet
  • Javascript (OK I haven't considered this because I don't know Javascript very well, but it seems possible.)

What is the best appro开发者_运维知识库ach?


In Plone 4 and greater, you can register the globalnav viewlet as a content provider:

<adapter
    name="globalnav"
    for="*
         zope.publisher.interfaces.browser.IDefaultBrowserLayer
         *"
    factory="plone.app.layout.viewlets.common.GlobalSectionsViewlet"
    provides="zope.contentprovider.interfaces.IContentProvider"
    />

and then include it in your homepage template or main_template using:

<tal:block tal:replace="structure provider:globalnav"/>


The only on the front page bit is the tricky part. You could use your GS profile to mark the front page with a special, one-off interface and then use ZCML to register the plone.global_sections viewlet for the IPortalFooter manager for that context and only that context:

<browser:viewlet
    name="plone.global_sections"
    for="my.special.IFrontPage"
    manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
    class="plone.app.layout.viewlets.common.GlobalSectionsViewlet"
    permission="zope2.View"
    />

You could also use this to then register a dummy, empty plone.global_sections viewlet for IPortalHead instead of using display: none;

<browser:viewlet
    name="plone.global_sections"
    for="my.special.IFrontPage"
    manager="plone.app.layout.viewlets.interfaces.IPortalHeader"
    class="my.special.EmptyViewlet"
    permission="zope2.View"
    />


I liked both suggestions, but I ended up doing the following (because I couldn't see how to do everything I wanted with the other suggestions):

<browser:viewlet
        name="trueblade.phoenix.footer2"
        manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
        class=".footer2.MyGlobalSectionsViewlet"
        template="footer2.pt"
        permission="zope2.View"
        />

With footer2.py like this (to subclass and nothing else):

from plone.app.layout.viewlets.common import GlobalSectionsViewlet

class MyGlobalSectionsViewlet(GlobalSectionsViewlet):
    pass

And footer2.pt like this (everything the same but the CSS id):

<tal:sections tal:define="portal_tabs view/portal_tabs"
 tal:condition="portal_tabs"
 i18n:domain="plone">
<h5 class="hiddenStructure" i18n:translate="heading_sections">Sections</h5>

<ul id="footer2"
    tal:define="selected_tab python:view.selected_portal_tab"
    ><tal:tabs tal:repeat="tab portal_tabs"
    ><li tal:define="tid tab/id"
         tal:attributes="id string:portaltab-${tid};
                        class python:selected_tab==tid and 'selected' or 'plain'"
        ><a href=""
           tal:content="tab/name"
           tal:attributes="href tab/url;
                           title tab/description|nothing;">
        Tab Name
        </a></li></tal:tabs></ul>
</tal:sections>

And CSS like this (to display footer2 on the front page only):

#footer2 {
    display: none;
}

.section-front-page #footer2 {
    display: block;
    margin: 1em;
}

And of course, a copy of the default footer styles for footer2:

#footer2 {
    clear: both;
    font-size: 80%;
    background: #ddd;
    /* ensure top navigation dont touches portlets, content etc.. #10491 */
    margin: 0 0 1em 0;
    text-align: center;
}
#footer2 li {
}
#footer2 li a {
    display: inline-block;
    padding: 0.5em 1em 2em 1em;
    background: #ddd;
    min-width: 6em;
    white-space: normal;
    /*TODO: Once we have removed the whitespace from the nav template, this can be put back*/
    /*border-bottom: 0.1em solid White;*/
    border-right: 0.1em solid white;
}

#footer2 .selected a,
#footer2 a:hover {
    background: #205c90;
    color: White;
}
#footer2 .selected a:hover {
    background: #ddd;
    color: #205c90;
}


There's a much less time consuming and non-intrusive approach, by not using viewlets, but portlets.

Products.ContentWellPortlets allows you to place portlets above and below the content.

I had written an addon, which is addressing that: adi.dropdownmenu. You can use it, unassign the "Extended navigation"-portlet (delivered of collective.portlet.sitemap) above the content and assign one below the content, set target-depth to 1, that's it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号