I have solved this by using macros instead of just trying to *include* the TAL snippit.

I wrapped the snippit in a tag like this:

<metal:block define-macro="lister" tal:omit-tag="">
</metal:block>

and called it on each tempalte that uses it liek this:

<metal:block use-macro="context/templates/widgets/template-lister/macros/lister">
</metal:block>



Erik Myllymaki wrote:
I am trying to separate out small bits of HTML that are used on many pages of a site.

In one case I use a secondary navigation on some pages in the right column that is supposed to look in the containing folder's sub-folders and list the Page Templates that is finds there.

I create a folder called /templates/widgets and within there I have a Page Template called template-lister.

<h2><strong>Quick Links</strong></h2>
<ul tal:define="ztu modules/ZTUtils;
raw python:context.objectValues('Folder');
location_folder_list python:ztu.LazyFilter(raw, skip='View')">

    <li tal:repeat="location_folder location_folder_list">
    <a href="" tal:attributes="href location_folder/absolute_url"
       tal:content="location_folder/title">Location Title</a>

<span tal:define="raw python:location_folder.objectValues('Folder'); office_folder_list python:ztu.LazyFilter(raw, skip='View')">
        <span tal:repeat="office_folder office_folder_list">
             <span tal:content="office_folder/title" >title</span>

<ul tal:define="raw python:office_folder.objectValues('Page Template'); posting_list python:ztu.LazyFilter(raw, skip='View')">
               <li tal:repeat="posting posting_list"
                        tal:condition="posting_list">
                   <a href="" tal:attributes="href posting/absolute_url"
                         tal:content="posting/title">Posting Title</a>
               </li>
               <li    tal:condition="not: posting_list">
                  No Postings at this time
               </li>
            </ul>
        </span>
        </span>
    </li>
</ul>


If I put this code directly in each Page Template that uses it, it works fine, but when removed from each Page Template and called like so:

<span tal:content="structure context/templates/widgets/template-lister" tal:omit-tag="" />

it uses the context of the "/templates/widgets" folder and does not work.

Because this bit of TAL is used on many pages and the style of it changes often, I really want to pull it out into one place for easy updating.

I know I am missing something elemental here ...

Thanks for any advice.
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to