Description
How to change the active view of a Plone content item programmatically
Dynamic views are views which the content editor can choose for his/her content from Display... drop down menu in the green edit frame.
By default, Plone comes with dynamic views for
Dynamic view can be skins template or BrowserView. Dynamic view machinery only cares about the path name coming after the context object.
Products.CMFDynamicViewFTI.browserdefault.BrowserDefaultMixin.getAvailableLayouts() returns the list of known layouts like following:
[('folder_summary_view', 'Summary view'),
('folder_tabular_view', 'Tabular view'),
('atct_album_view', 'Thumbnail view'),
('folder_listing', 'Standard view'),
('product_listing', u'Product listing')]
layout_ids = [ id for id, title in self.portal.folder.getAvailableLayouts() ]
self.assertTrue("product_list" in layout_ids)
ノート
Need code example.
self.portal.folder.setLayout("product_listing")
Default page is the content chosen to display when the visitor arrives to URL without any subpages or views selected.
This is useful if you are doing folder listing manually and you want to filter out the default view.
default_page helper view can be used to manipulate default pages.
Getting default page
# Filter out default content
container = self.getListingContainer()
default_page_helper = getMultiAdapter((container, self.request), name='default_page')
# Return content object which is the default page or None if not set
default_page = default_page_helper.getDefaultPage(container)
Setting default page can be done as simple as setting default_page attribute of the folder to be the id of the default page:
folder.default_page = "my_content_id"
More information can be found in
If you need to have a view for few individual content items only it is best to do using marker interfaces.
For more info
This is what Plone Folder content views out of the box