Zope3非获取式的引用模板和资源

Zope3非获取式的引用模板和资源
Zope2的获取技术存在一个广泛的不确定性,且效率不高;所以在Zope3中,对资源的调用,取消了获取,调用资源文件时,需要显示在ZCML注册。
The portal_skins tool from CMF relies on Zope 2 Acquisition. In Zope 3 this feature is dropped because it allows a wide range of dirty tricks, which makes code work like magic. Another reason to not want acquisition is performance. While acquiring an attribute the zope security machinery has to be used.
In Zope 3 Templates are connected to a browser view for a given context with ZCML. In addition those templates are guarded with a permission.
example:

<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser"> <browser:page  for="Products.plonehrm.interfaces.worklocation.IWorkLocation"  name="worklocationview"  class=".worklocation.WorkLocationView"  permission="zope.Public"  template="worklocation.pt"  allowed_interface=".interfaces.IWorkLocationView" /> </configure>for: The for directive specifies which interface the context should provide to allow calling the view. In this example the view can only be called on a content object that provides IWorkLocation.
name: This is the name that can be used in the URL to call the view.
class: This is the class which provides the BrowserView class for the template. Within the template the methods of this class are available through the view variable e.g.:
tal:define="mytitle view/Title"permission: This directive allows you to hook up the Zope security to guard access to the template. zope.permname calls the zope3 machinery. Within Five also zope2.permname and cmf.permname are available, so when working with Zope 2 we should use e.g. cmf.ModifyPortalContent
template: this directive allows you to hook your template to the view.
allowed_interface: this directive is another type of security. Normally python permits even calls to private methods, by defining an Interface here, you strictly provide the publically available methods defined in the interface.
Typically all HTML templates are placed in a package named browser because it handles calls from a web browser. When handling different types of interaction you should put those in a separate package e.g. ftp.
When you create a browser view, make sure that it doesn’t have the same name as a template that can be reached via acquisition. If you ignore this advise, you might run into a situation where sometimes the page template if found and in other cases the browser view.
Images, css and javascriptNOTE: by putting images in a skins folder and providing a .metadata will allowcachefu to add correct headers. Z3 resources are not picked up yet. css, js are kss are no problem since they are served by the resource registry.In Zope 2 we used to go through all images into a skin and rely on acquisitioning of the portal_skins tool to find those files. In Zope 3 we call these files resources and we need to explicitly make these files available with ZCML.
example:
<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser">  <!-- Individual Resources -->  <browser:resource name="zest.css" file="zest.css" />  <!-- Entire Directory with resources -->  <browser:resourceDirectory name="images" directory="images" /> </configure>The first option is used for publishing a specific resource, the second option is comparable to the old portal_skins skins folder.
Resources are published through a special namespace in Zope 3: http://localhost/++resource++resourcename
example:
http://localhost/++resource++zest.css http://localhost/++resource++images/image1.jpg
设置