plonetemplate-talzpt

Omit site site in returned result when using getPath in Plone page templates


I have a piece of TALES for a page template in Plone which looks through the results of a collection and inserts them into a box (similar to that of a collection portlet)

I have an issue in getting a URL from the returned items, I have been using getPath however it returns the site name, so my URLS end up being http://mysite.com/ThePloneSite/folder/page instead of just http://mysite.com/folder/page, currently my example TALES is as follows:

<a tal:attributes="href string:${item/getPath}/view">Item</a>

I have tried every variation I can imagine but I can't remember them all so here's a couple that don't work:

(this returns nothing)

<a tal:attributes="href item/absolute_url">Item</a>

this gives me a traceback, complaining about "getpath":

<a tal:attributes="python:item.getObject().absolute_url()">Item</a>

The only reason the site name being in the link is annoying is that in order to access the "State" and "Display" buttons you must click "View" after originally clicking on the link

NOTE: the last example works when you're using getFolderContents however I understand returning results from a collection are different.

Any help would be greatly appreciated, thanks.

EDIT Traceback for absolute version:

Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PageTemplates.ZopePageTemplate, line 334, in _exec
  Module Products.PageTemplates.ZopePageTemplate, line 431, in pt_render
  Module Products.PageTemplates.PageTemplate, line 79, in pt_render
  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 946, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 405, in do_startTag
  Module zope.tal.talinterpreter, line 482, in attrAction_tal
  Module Products.PageTemplates.Expressions, line 225, in evaluateText
  Module zope.tales.tales, line 696, in evaluate
   - URL: /peacehospice/portal_skins/custom/home_page_view
   - Line 200, Column 12
   - Expression: <PythonExpr alldoc.getObject().absolute_url()>
   - Names:
      {'container': <PloneSite at /peacehospice>,
       'context': <ATDocument at /peacehospice/front-page>,
       'default': <object object at 0x7fbed9313b30>,
       'here': <ATDocument at /peacehospice/front-page>,
       'loop': {u'alldoc': <Products.PageTemplates.Expressions.PathIterator object at 0x7fbebcd20c50>},
       'nothing': None,
       'options': {'args': ()},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x7fbebde89680>,
       'request': <HTTPRequest, URL=http://demo.kcsts.co.uk/front-page/home_page_view>,
       'root': <Application at >,
       'template': <ZopePageTemplate at /peacehospice/home_page_view used for /peacehospice/front-page>,
       'traverse_subpath': [],
       'user': <PropertiedUser 'dan'>}
  Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__
   - __traceback_info__: alldoc.getObject().absolute_url()
  Module PythonExpr, line 1, in <expression>
  Module AccessControl.ImplPython, line 716, in guarded_getattr
  Module AccessControl.ImplPython, line 658, in aq_validate
  Module AccessControl.ImplPython, line 552, in validate
  Module AccessControl.ImplPython, line 322, in validate
  Module AccessControl.ImplPython, line 749, in raiseVerbose
  Module AccessControl.ImplPython, line 726, in item_repr
  Module plone.app.contentlisting.catalog, line 29, in __repr__
  Module plone.app.contentlisting.catalog, line 74, in getPath
  Module Products.ZCatalog.CatalogBrains, line 51, in getPath
AttributeError: getpath

TALES for getting content of collection:

<div id="all-documents" tal:define="allDocsBatch python:context.documents.alldocuments.results(b_start=b_start,b_size=10)">
  <h3>All Documents</h3>
  <div class="tabbedWrapper">
    <div class="item" tal:repeat="alldoc allDocsBatch">
      <p>
        <img tal:replace="structure alldoc/getIcon" />
        <a tal:attributes="href python:alldoc.getObject().absolute_url()" tal:content="alldoc/Title" />
        <span class="tags" tal:condition="alldoc/Subject" tal:define="alldoctag alldoc/Subject">
          <a tal:repeat="tag alldoctag" tal:content="tag"
             tal:attributes="href string:${context/portal_url}/@@search?Subject:list=${tag}"/>
        </span>
      </p>
    </div>
  </div>
</div>

EDIT #2

NOTE found a link http://copilotco.com/mail-archives/plone-users.2007/msg05113.html which may help but haven't had a chance to look at it just yet.


Solution

  • If item is a catalog brain (as in your example) you need to call item/getURL. absolute_url is for real objects.