[Zope] ZPT & contents slot

J Cameron Cooper zope-l at jcameroncooper.com
Tue Jun 21 16:16:11 EDT 2005


John Poltorak wrote:
> If I create a macro which defines a slot called 'content', is there any 
> way to have that slot populated by a file with a specific name if it 
> exists in a folder? 
> 
> What I'd like to do is create a structure text file, in each of the 
> folders A B C and have it automatically loaded into a content slot of a 
> master template whenever the options A B C are selected.
> 
> Can I do that, and if so how?
> 
> I have spent all day looking at ZPT references and have no idea if what 
> I'd like to do is possible.

You don't have to involve macros::

  <div>I'm a header</div>

  <p tal:condition="exists:context/stxfile"
     tal:replace="structure context/stxfile/CookedBody">
    This is sample page content
  </p>

  <div>I'm a footer</div>

If 'stxfile' can be aquired, what it renders will be included as page 
structure. (You may need to use a different method one the end of the 
path to render the object; for Documents, this is 'CookedBody'.) 
Otherwise, nothing will be rendered, though you could add a block with 
the oposite condition to supply a default action.

If you do not want the effects of acquisition, you may say instead::

   tal:condition="exists:context/aq_explicit/stxfile"

since Zope assumes you generally want acquisition.

		--jcc
-- 
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


More information about the Zope mailing list