How to implement backlinks ? I imagine we could use ZCatalog,

or.. brute force!!

<dtml-let thispage=id>
<dtml-in "aq_parent.objectValues(spec=ZWiki Page)" sort=id>
<dtml-unless ".string.find(.getitem(sequence-item).raw,thispage) == -1">
<dtml-var "_.getitem(id)()"> <br>
</dtml-unless>
</dtml-in>
</dtml-let>

Cool. I guess I'll move this code to a DTML method.


use http://zwiki.org/zwikidir/templates/defaults/backlinks.dtml/view_source <--- Dead Link.


2002/11/05 22:46 GMT (via web):
The "brute force" code avobe has problems:

Next workaround: build HTML links in the dtml code...don't forget to append to the proper URL, not just relative..


via JohnGreenaway, Here's the catalog way to do it:
<dtml-let 
thisfolder=folder
thispage=title_or_id
thisid=id
thiscid=canonicalId
backlinks="
(thiscid == thisid and Catalog(canonicalLinks=thiscid)) 
or Catalog(canonicalLinks=thiscid) + Catalog(links=thisid)
">
<dtml-in backlinks sort=title_or_id>
<dtml-let 
blpage=title_or_id
blid=id
bllinktitle="thisfolder[blid].linkTitle()"
>
<a href="&dtml-wiki_url;/&dtml.url_quote-blid;" title="&dtml-bllinktitle;">
<dtml-var blpage></a> 
</dtml-let>
</dtml-in>
</dtml-let>


comments:

need wiki actions -- Wed, 13 Aug 2003 23:59:32 +0000 reply
Why not use wiki actions... like Wakka does? {{backlinks}} does it in wakka!

need wiki actions --SimonMichael, Thu, 14 Aug 2003 00:11:41 +0000 reply
We spell that like this:

 <dtml-in "backlinksFor(id())">
  <dtml-var "wikilink('['+Title+']') ">
 </dtml-in>

Does the above code break under Zwiki 0.22 ?

I removed title_or_id from the catalog.. changed the above to use Title instead.

SubWiki note --DeanGoodmanson, Tue, 23 Sep 2003 15:39:40 -0700 reply
When you have SubWikis, and a catalog, the canonicalLink version of the backlinks above will display every linked page in the wiki and subwikis.

This can be a good thing, but probably not as blasts the namespacing feature of subwiki's. If this were a good thing, you'd probably want expect SearchPage to include sub-wiki's, which it doesn't. (And it won't fill in teh appropriate path/URL for the subwiki pages listed.)

sort() --DeanGoodmanson, Wed, 01 Oct 2003 11:24:10 -0700 reply
I had a couple failed attempts on alphabetizing the list returned from a backlinks call with "sort()" Any suggestions? I can post my failed attempts if it would help. It looks like the backlinks page actually sorts this, but that's zpt, not dtml..

If it's not simple, would it be unreasonable to add an alphabetize flag into the pages and/or backlinks calls?