开发者

Display Actions Only For Specific Folders

I have added a custom CMF Action at /mysite/portal_actions/object/rename. The value for "Condition (Expression)" field is python:plone_context_state.is_folderish() or plone_context_state.is_default_page(), that makes the action visible on every folder's tab. I want it show only on tabs 开发者_如何学编程of folder1, folder2 and folder3. What should I use for Condition field?


You have several options; the condition expression can be extended almost infinitely.

By folder id

The obvious test would be to test for a set of folder ids:

python:(plone_context_state.is_folderish() or plone_context_state.is_default_page()) and
        folder.getId() in ('folder1', 'folder2', 'folder3')

Use collective.flag

collective.flag let's your content editors determine where the tab should show up. It adds a simple boolean checkbox to your content, and you could easily test for that flag being set on your folders. The flag only shows up on content types that have the correct interface, so you could easily do this

python:(plone_context_state.is_folderish() or plone_context_state.is_default_page()) and 
        folder.restrictedTraverse('@@plone_interface_info').provides('collective.flag.interfaces.IFlaggableObject')

Use a script test

You can use any acquirable method for your test, including a Python script in the skin. Not the best practice, but it may just give you the extra flexibility you need.

python:(plone_context_state.is_folderish() or plone_context_state.is_default_page()) and
        folder.yourScriptName()

Just remember to test for conditions on folder.


python:(plone_context_state.is_folderish() and (object.getId() == 'folder1' or object.getId() == 'folder2' or object.getId() == 'folder3')) or (plone_context_state.is_default_page() and (plone_context_state.parent.getId() == 'folder1' or plone_context_state.parent.getId() == 'folder2' or plone_context_state.parent.getId() == 'folder3'))

something like this. You can use the folder path to be sure they're exacly those folders and not just folders with those ids.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜