Tags:
create new tag
view all tags

Question

Is there a way to create a link in c:/twiki/templates/view.pattern.tmpl that will open a topic which matches the exact name of the selected topic minus specific text that appears at the end of the name?

Background

We would like every topic in our wiki to have a corresponding, but separate “Comments” topic.

For example:

  • Main.TopicNameAlpha
  • Main.TopicNameAlphaComments

  • Main.TopicNameBeta
  • Main.TopicNameBetaComments

What I Can Do

I’m able to create a single link in c:/twiki/templates/view.pattern.tmpl that I can use to view Main.TopicNameAlphaComments from Main.TopicNameAlpha and to view Main.TopicNameBetaComments from Main.TopicNameBeta. Here’s the following line of code I use to accomplish this:


   * <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%Comments">Topic</a>

What I Want to Do

Create a single link in c:/twiki/templates/view.pattern.tmpl that I can use to view Main.TopicNameAlpha from Main.TopicNameAlphaComments and to view Main.TopicNameBeta from Main.TopicNameBetaComments. Based on the line of code I use above, the relevant code might look similar to one of these examples (I know they aren't technically accurate, but I’m providing them to demonstrate/help explain):

%NameThatMatchesAllButTheCommentsPortionOfThisCommentsTopic%
  • or, put another way (topic name minus the “Comments” portion):
%TOPIC%-*Comments
  • or maybe:
%TOPIC%excludetopic=“*Comments”
  • or maybe:
%TOPIC%/%EXCLUDE {“*Comments”}%

Environment

TWiki version: TWikiRelease04Sep2004
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Windows XP Professional Service Pack 1
Web server: Apache 1.3.34 (Win32)
Perl version: 5.8.7-5 (Cygwin)
Client OS: Windows XP Professional Service Pack 2
Web Browser: Internet Explorer 6.0
Categories: Skin

-- JasonVensel - 06 Mar 2006

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

Hm, should be doable by some SSP-wizardry (SSP = SpreadSheetPlugin).

For example:

See the raw source for how I did this. Hint: $SEARCH allows RegularExpressions. If you don't need this you may use $FIND instead.

-- FranzJosefSilli - 06 Mar 2006

Excellent! Franz, thank you for this solution. This meets what I was looking for.

SOLUTION

For future readers, here's what I did based on FranzJosefSilli's response:

  • Open c:/twiki/templates/view.pattern.tmpl.
  • Locate the following line (it should be located around line 81 or so):


%TMPL:DEF{"toolbar"}%<div class="twikiToolBar"><div>

  • Add the CALC lines and replace the href "link" lines with the following:


%TMPL:DEF{"toolbar"}%<div class="twikiToolBar"><div>

%CALC{"$SET(my_topic,%TOPIC%)"}%
%CALC{"$SET(my_exclude,[D][iscussion])"}%

%CALC{"$SET(my_pos,$SEARCH($GET(my_exclude),$GET(my_topic)))"}%
%CALC{"$SET(my_len,$LENGTH($GET(my_exclude)))"}%
%CALC{"$SET(my_result,$REPLACE($GET(my_topic),$GET(my_pos),$GET(my_len),))"}%

   * <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%CALC{"$GET(my_result)"}%">Topic</a>
   * <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%Discussion">Discussion</a>
   * %EDITTOPIC%
   * <a href="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/%TOPIC%?skin=kupu">WYSIWYG</a>
   * <a href="%SCRIPTURLPATH%/attach%SCRIPTSUFFIX%/%WEB%/%TOPIC%">Attach</a>
   * <a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%?skin=print.pattern%REVARG%">Printable</a>
</div><div class="twikiRevInfo"><span class="twikiGrayText"><span class="twikiToolbarElem"><nop>%WEB%.%TOPIC%</span><span class="twikiToolbarElem">%REVINFO%</span><span class="twikiToolbarElem"><a href="#TopicEnd">topic&nbsp;end</a></span></span></div></div>%TMPL:END%

-- JasonVensel - 07 Mar 2006

The solution described above works for the most part. However, I ran into a slight issue.

I'll use the following topics to describe the issue:

  • Policies.SalesTaxes
  • Policies.SalesTaxesDiscussion
and
  • Policies.IRSMileageRate
  • Policies.IRSMileageRateDiscussion
and
  • Policies.ItemSetupInASiteDatabase
  • Policies.ItemSetupInASiteDatabaseDiscussion

Each of the links at the top (Topic, Discussion, Edit, WYSIWYG, Attach, and Printable) is always enabled/active. Normally, I use our wiki site in the following manner:

  1. From the Policies.SalesTaxes topic, I click the Discussion link to open the Policies.SalesTaxesDiscussion topic. This works just fine.
  2. After viewing and/or editing the Policies.SalesTaxesDiscussion topic, I click the Topic link and am returned to the Policies.SalesTaxes topic. This works just fine.
  3. In addition, because the Topic link is never disabled/inactive, when I have the Policies.SalesTaxes topic open and click the Topic link, I expect the Policies.SalesTaxes topic to simply re-load. In fact, this is how it works and there are no issues.

However, there is an issue with step 3 of the above process when the non-discussion topic's wiki name is GREATER THAN 14 characters. Here's what happens:

  1. First consider the Policies.ItemSetupInASiteDatabase topic. Important: Note that the ItemSetupInASiteDatabase portion of the topic name is greater than 14 characters. Counting from left to right, the "t" in "Site" is the 15th character in the name.
  2. Now, from the Policies.ItemSetupInASiteDatabase topic, I click the Discussion link to open the Policies.ItemSetupInASiteDatabaseDiscussion topic. This works just fine.
  3. After viewing and/or editing the Policies.ItemSetupInASiteDatabaseDiscussion topic, I click the Topic link and am returned to the Policies.ItemSetupInASiteDatabase topic. This works just fine.
  4. Again, because the Topic link is never disabled/inactive, when I have the Policies.ItemSetupInASiteDatabase topic open and click the Topic link, I would expect the Policies.ItemSetupInASiteDatabase topic to simply re-load. However, this is NOT how it works. Instead, the NOTE: This Wiki topic does not exist yet message appears, prompting me to do a full text search for teDatabase (that is not a mis-type; it is "teDatabase"). It also warns me that creating a page with this topic name is not recommended because it's not a wiki word.
  5. Based on my testing, I've discovered that this happens for any topic with a name that is greater than 14 characters.
  6. I also discovered the following:
    1. The web name of the topic is not a factor in the 14-character count. E.g., Policies (one of our web names) consists of 8 characters whereas Instructions (another one of our web names) consists of 12 characters; the 14 character issue is true for topics in both webs.
    2. This isn't an issue for topics that have exactly 14 characters.
    3. For topic names that exceed 14 characters, the name that appears in the full text search box of the "NOTE: This Wiki topic does not exist yet" page is the entire remaining portion of the topic name, beginning with the 15th character.
  7. The 14-character issue appears to stem from the $LENGTH setting above. This setting uses my_exclude, which is [D][iscussion], which happens to be 14 characters. I verified this by changing my_exclude to Discussion (which is only 10 characters) and then trying the steps described above with the Policies.IRSMileageRate topic (the topic name is exactly 14 characters).
  8. With my_exclude set to [D][iscussion], clicking the Topic link with Policies.IRSMileageRate already selected simply re-loads the page. This is how I want it to function for all non-discussion topics.
  9. With my_exclude set to Discussion, clicking the Topic link with Policies.IRSMileageRate already selected opens the "NOTE: This Wiki topic does not exist yet" page with "Rate" in the full text search and a warning that this topic name isn't a wiki word. The "R" in "Rate" is the 11th character in the Policies.IRSMileageRate topic name.

Conclusion I need to modify:

%CALC{"$SET(my_len,$LENGTH($GET(my_exclude)))"}%
Ideally, I'll be able to set this to some numeric value high enough to include all my topics. I haven't worked with SSP at all, so I'm going to do a little research on it and the $LENGTH variable, do some trial and error testing by inserting different values, and then post the results here when I'm done.

-- JasonVensel - 08 Mar 2006

TEST 1

* Set my_len to a numeric value. For this test, I'll set it to 16.

Replacing:

%CALC{"$SET(my_len,$LENGTH($GET(my_exclude)))"}%
with:
%CALC{"$SET(my_len,16)"}%
worked. Based on limited testing, this seems to work. It hasn't caused any problems. The only issue with using this is that I'll have to replace 16 with some number greater than the longest wiki topic name in our TWiki installation.

TEST 2

* Omit my_len parameter entirely.

Deleted:

%CALC{"$SET(my_len,16)"}%

And the replaced:

%CALC{"$SET(my_result,$REPLACE($GET(my_topic),$GET(my_pos),$GET(my_len),))"}%
With:
%CALC{"$SET(my_result,$REPLACE($GET(my_topic),$GET(my_pos),))"}%

This didn't work. From a "discussion" page, clicking Topic just reloaded the "discussion" page; it didn't return me to the main topic.

TEST CONCLUSION

I've decided to use:

%CALC{"$SET(my_len,100)"}% 

And see how it runs for awhile. I'm marking this Answered. If anything else related comes up, I'll update this post.

Much thanks again to FranzJosefSilli for his invaluable input.

-- JasonVensel - 08 Mar 2006

Hm, the length is needed if you want to cut out a subtext from within another text (as far as I understood the SpreadSheetPlugin function description, didn't check the code). If you just want to snip of the subtext from the end of the string ... Well, I didn't that much testing. smile Maybe Peter has more insight.

-- FranzJosefSilli - 08 Mar 2006

Setting it to 100 has worked so far. I may adjust (shorten) it based on the character length of our longest topic. Otherwise, I'm content to leave it like this unless someone knows of a reason against it.

-- JasonVensel - 09 Mar 2006

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2006-03-09 - JasonVensel
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.