I'm looking for a way to programmatically set some footer portlets in Plone 5. I have a script which uses the plone.api to create new content, but I don't see an similarly elegant approach for creating a new static portlet in target portlet manager.
After some digging, this package is looking like my best bet https://github.com/collective/wm.sampledata
Specifically this "addPortlet" utility
Wouldn't using GS be the easiest way? Look how Plone core installs portlets with GS perhaps?
I'll vouch for the GS way of adding a portlet at add-on activation time. Was really easy to do.
Agree with @vangheem and @tkimnguyen, here's an example for a header- and a footer-portlet, in conjunction with one of my fav-addons "Products.ContentWellPortlets":
http://svn.plone.org/svn/collective/adi.simplestructure/trunk/adi/simplestructure/profiles/default/portlets.xml
@ida, @tkimnguyen and @vangheem thank you for pointing this out, looks much simpler than what I was doing. The addPortlet approach did work btw, though it caused all sorts of mental contortions. Now I have to go find some use for my "hacky" approach. .
I'm also looking at documentation on removing portlets here: http://docs.plone.org/develop/plone/functionality/portlets.html#hiding-unwanted-portlets
IF you want to add a new Static Custom portlet pro grammatically than you have to do certain thing as as following
- Create your own custom addon product (Basic) using paster or mr.bob product skeleton script in your src directory,
- once your product skeleton has been created then you should create a portlets directory into your own product and register this directory in configure,zcml( ) .
- Inside the Portlet directory you have to create one more configure.zcml where you define your prottlet name and its functionality
e.g
<plone:portlet
name="Product.name.StaticPortlet"
interface=".StaticPortlet.IUCountPortlet"
assignment=".StaticPortlet.Assignment"
renderer=".StaticPortlet.Renderer"
addview=".StaticPortlet.AddForm"
editview=".StaticPortlet.EditForm"
/> - Create StaticPortlet.py and StaticPortlet.pt where you define your html code anf python code logic.
- Refer Creating, Customizing, and Assigning Portlets Automatically here
@jitesh43 this isn't what I was looking for, as this defines a brand new portlet. I wanted to be able to control an existing portlet type (Static portlet). I was able to successfully do so by borrowing ideas from https://github.com/collective/wm.sampledata.
Ok, David Bain thanks for the update.
can you share your final code?