You are not logged in Log in Join
You are here: Home » Members » camil7 » Silva Documentation and HowTo's » Distinguish view and preview by request attribute. » tip_view

Log in
Name

Password

 

Created by ZopeOrgSite . Last modified 2003-12-31 23:47:24.

If You write page templates to render content, there are a few places, where the layout differs, depending on if you look at it via the index_html or the preview_html. If the differences are large, it is best to write two templates, and have a script do the dispatch.

However it the difference is small (e.g. when rendering links to other Silva objects, you may want to append /preview_html to the url, nothing else), you can use one template and check for preview on the fly, e.g. by saying:

<tal:init define="global is_preview request/other/is_preview | nothing" />

and then do something like:

 <a href="content_link" 
    tal:attributes="href python:content_link.absolute_url(1) + test(is_preview,'/preview_html,'') >  

This saves you the efford of maintaining two templates.

However the default Silva layout does not support the magic of inserting an is_preview in the 'request'; You have to hack the /silva/index_html by inserting a line like:

 if view_method=='preview':
     container.REQUEST.set('is_preview',1)

XXX: this does not work for the SMI-preview; here You would have to hack /silva/service_views/Silva/edit/tab_preview, too, which You can find in the view/edit subdirectory of the Silva product.