[Zope-dev] Reading contents of a Page Template
J Cameron Cooper
jccooper at jcameroncooper.com
Mon Aug 18 16:05:44 EDT 2003
> I have a requirement to create a SiteMap for my site.
> My site is dynamically built from the Zope tree structure.
> Folder and Sub Folders need to appear as a tree structure and need to
> be sorted by name and date.
> I have viewed the examples in the Examples folder in ZMI and gotten a
> general Idea of how to get the files within a specific folder.
> But I need to be able to go through the whole set of folders and sub
> Folders and create the SiteMap and not just for a single folder .
> Is there some While- Do Loop which I can use to Loop through till I
> reach the Lowest rung in a Tree for each and every Folder and create a
> Site Map.
Basic CS. Q: How do you walk a tree? A: Recursion.
Try this Page Template. Name it 'recurse'::
<ul>
<li tal:repeat="item here/objectValues">
<span tal:content="item/getId" tal:omit-tag="">An object</span> :
<span tal:content="item/title" tal:omit-tag="">A title</span>
<span tal:condition="python:item.meta_type=='Folder'"
tal:content="structure item/recurse">A Folder listing</span>
</li>
</ul>
The condition check is pretty primitive. Probably a better one would
check for the presence of the objectValues method like
tal:define="folderish nocall:item/objectValues"
tal:condition="folderish | nothing"
This will construct a nested HTML unordered list of your tree from the
place where you called it (from inside a valid HTML page.) You can of
course tweak the display code.
There are also products that will create site maps. Search around.
> Also Each of these folders has an index_html page template which can
> be linked from the SiteMap that is created.
> Each of the index_html files has a number of anchor tags.
> These Tags are for moving within the Page.
> I need to be able to include these Tage as well in My SiteMap ...
> CAN I GET THESE ANCHOR TAG LINKS ON EACH PAGE BY READING THROUGH THE
> CONTENT OF EACH OF THESE PAGE TEMPLATES?
> IS THERE SOME OTHER WAY TO DO ALL THESE ???
You know that all-caps is considered yelling rather than empahsis,
right? Generally not a good idea when asking for help.
Anyway, this is harder. You would have to render and then parse the HTML
to get the tags. You could have a script that does that on leaves, or
create (either offline or dynamically) children (by inheriting
ObjectManager in a custom class) or a list property of the object
representing the available anchor tags. You could also do this by hand.
Maybe you could replace your documents with folders containing the
various anchors as separate segments composited in the index_html. The
segments could be easily found that way, although you'd have to make
your tree-walker recognize them as leaves instead of containers.
--jcc
--
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."
More information about the Zope-Dev
mailing list