Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="https://plone.org/documentation/kb/customization-for-developers/viewlets" rel="nofollow">viewlets</a> for both usecases. A viewlet can be inserted in different parts of the rendered page, depending on both the viewlet manager you register it to and and what interfaces the viewlet applies to.</p> <p>The viewlet manager determines the location the viewlet is inserted at, and the interface you register the viewlet for determines on what kind of URL the viewlet will be visible at. Registering for <code>"*"</code> means show everywhere, and registering it for <code>"Products.ATContentTypes.interfaces.IATDocument"</code> means it'll only be visible when viewing a Page.</p> <p>To see what viewlet managers are available and what viewlets are registered there, for any given URL, just add "/@@manage-viewlets" to the URL. There you can see that there is a <code>plone.abovecontent</code> and a <code>plone.abovecontenttitle</code> viewlet manager that would enable you to insert HTML there. Most of these are defined in the <code>plone.app.layout</code> package, and you'll need to find the interface that is registered with that name there (find it in your eggs directory of the buildout).</p> <p>You register a viewlet using ZCML, so you need to already have a python package that is loaded for your site. To insert an arbitrary template, simply register it with the <code>browser:viewlet</code> directive:</p> <pre class="lang-xml prettyprint-override"><code>&lt;browser:viewlet name="your.html.snippet" for="Products.ATContentTypes.interfaces.IATDocument" manager="plone.app.layout.viewlet.interfaces.IAboveContent" template="htmlsnippet.pt" permission="zope.Public" /&gt; </code></pre> <p>Now, a viewlet based on the <code>htmlsnippet.pt</code> template is registered for the <code>plone.abovecontent</code> viewlet manager. That template is a full zope page template, so you can use things like internationalisation in there:</p> <pre><code>&lt;div i18n:domain="your"&gt; &lt;h3 i18:translate="html_snippet_header"&gt;This is a snippet of HTML that'll be injected into all Pages!&lt;/h3&gt; &lt;/div&gt; </code></pre> <p>You can also add a full browser view class to back up the viewlet, and the template can access that class via the "view/" namespace, so you could add a method there to return random text to be inserted.</p> <p>You can either manually enable the viewlet via the aforementioned '/@@manage-viewlets' URL or you can use a GenericSetup profile, where viewlets.xml let's you manage the registrations and ordering of viewlets:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt; &lt;object&gt; &lt;order manager="plone.abovecontent" skinname="My Theme" based-on="Plone Default"&gt; &lt;viewlet name="your.html.snippet" insert-before="*"/&gt; &lt;/order&gt; &lt;/object&gt; </code></pre> <p>For more information, I refer you to the <a href="https://plone.org/documentation/kb/customizing-main-template-viewlets" rel="nofollow">viewlets tutorial</a> on Plone.org.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload