I have created a viewlet which should show the editable part of plone pages within a folder. The result is entire structure of every page in this folder. I may be going wrong with the page template code. Any thoughts would be greatly appreciated.
viewlet code and catalog search:
class MyViewlet(grok.Viewlet):
grok.name('my-viewlet')
grok.order(0)
grok.context(Interface)
grok.viewletmanager(IBelowContent)
index=ViewPageTemplateFile('templates/templatefile.pt')
def update(self):
self.context = aq_inner(self.context)
self.project = self.getProject()
self.project_array = self.getProjectArray()
@memoize
def getProject(self):
portal_catalog = getToolByName(self.context, 'portal_catalog')
site = self.context.portal_url.getPortalObject()
folder_path = "/" . join(site.getPhysicalPath())
folder_path += "/afolder"
results = portal_catalog.searchResults({
'portal_type':'Document',
'path':{'query': folder_path,'depth': 1},
'sort_on':'getObjPositionInParent'
})
project_array = processResults(results)
if(project_array):
return project_array[0]
else:
return False
@memoize
def getProjectArray(self):
portal_catalog = getToolByName(self.context, 'portal_catalog')
portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state')
site = portal_state.portal()
folder_path = "/" . join(site.getPhysicalPath())
folder_path += "/afolder"
results = portal_catalog.searchResults({
'portal_type':'Document',
'path':{'query': folder_path,'depth': 1},
'sort_on':'getObjPositionInParent'
})
project_array = processResults(results)
if not project_array:
return False
for i in project_array:
i['class']='';
project_array[0]['class']='active'
return project_array
def render(self):
return self.index()
templatefile.pt:
<tal:block
tal:define="our_url context/@@plone_context_state/canonical_object_url;
home_url context/@@plone_portal_state/portal_url;"
tal:condition="python:our_url == home_url">
<div id="previous-projects-viewlet" class="respond">
<div id="projects">
<div id="projects-container">
<tal:block tal:repeat="project view/project_array">
<tal:block tal:define="iobject project/brain/getObject">
<div tal:attributes="id string:project-${repeat/project/index};
class string:${project/class} project;"
tal:content="structure iobject"/>
</tal:block>
</tal:block>
</div>
</div>
</div>
</tal:block>
Thanks Mathias. The problem was in the template file, it's the defined variable /getText to render just the page contents.
<tal:content="structure iobject/getText"/>