Tags:
create new tag
view all tags

Question

All my topics have a human readable H1 title, but the topic name can be Page01, Page02 etc. Therefore i'd like the notification e-mail to:

  • search the page for the first H1 and use that in stead of %TOPICNAME%
  • use %TOPICNAME% if no H1 is present

It would be great if someone could help me achieve this!

TIA,

Environment

TWiki version: TWikiRelease04x00x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: RH9
Web server: Apache 2.052
Perl version: 5.8.5
Client OS: winxp
Web Browser: ie6
Categories: Mail

-- JosMaccabiani - 16 Jun 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.

based on suggestions by Arthur and Martin in #twiki, I tried to include a SEARCH in mailnotify.tmpl:

%SEARCH{"m!\-\-+\+!" web="%WEB%" topic="%TOPICNAME% type="regex" scope="text" zeroresults="off" noheader="on" nosummary="on" format="$pattern(m!\-\-+\+!)"}%

This doesn't seem to work, there are no results and e.g. zeroresults="off" is ignored. Is there some other way?

-- JosMaccabiani - 17 Jun 2006

Your regexp seems to be missing a " after %TOPICNAME%.

But try to start out with something simpler, i.e.:

%SEARCH{"\-\-\-\+.*" web="%WEB%" topic="%TOPICNAME%" type="regex" format="$pattern(^\-\-\-\+*?\s([^\n\r]*).*)"}%

And then add options and circle in on the right formula from there.

-- SteffenPoulsen - 27 Jun 2006

Thanks for spotting the error! Indeed, using your search does return the result, and then setting nonoise="on" removes the noise as expected.

This is great! However, since mailnotify.tmpl works for all e-mail notification in all webs, and not every web uses the automatic page numbering system, I need an IF type statement that checks if a H1 is present and else just returns %TOPICNAME%.

I've looked at both %IF% and %CALC{$IF}% but I can't find (yet) how to check for the existence of the regexp...

-- JosMaccabiani - 27 Jun 2006

Woohoo! After some more fiddling, I did get it working:

 <a href="%SCRIPTURL{"compare"}%/%WEB%/%TOPICNAME%">%IF{"%SEARCH{"\-\-\-\+.*" web="%WEB%" topic="%TOPICNAME%" type="regex" scope="text" nonoise="on" format="%TOPICNAME%"}%" then="%SEARCH{"\-\-\-\+.*" web="%WEB%" topic="%TOPICNAME%" type="regex" scope="text" nonoise="on" format="<b>$pattern(^\-\-\-\+*?\s([^\n\r]*).*)</b>"}%" else="<b>%TOPICNAME%</b>"}%</a>

-- JosMaccabiani - 27 Jun 2006

This is untested, but should work with/without some tweaks. The idea is to assign the pattern to a spreadsheet variable, then to output the variable if not empty, else to output the topic name:

format="$percntCALC{$SET(title, $pattern(^\-\-\-\+*?\s([^\n\r]*).*))$IF($EXACT(, $TRANSLATE($GET(title), $comma, ;), %TOPICNAME%, $GET(title))}$percnt"

The $TRANSLATE() takes care of defusing commas before the compare (the title might contain commas.)

-- PeterThoeny - 27 Jun 2006

Jos: As a service to others using these plugins you might want to file your adventures as hints on the CompareRevisionsAddOnDev and the MailerContribDev topic?

- Instant bonus points from this major direction smile

-- SteffenPoulsen - 27 Jun 2006

I tried using both of these,and neither gives great output. <a href="%SCRIPTURL{"compare"}%/%WEB%/%TOPICNAME%">%IF{"%SEARCH{"\-\-\-\+.*" web="%WEB%" topic="%TOPICNAME%" type="regex" scope="text" nonoise="on" format="%TOPICNAME%"}%" then="%SEARCH{"\-\-\-\+.*" web="%WEB%" topic="%TOPICNAME%" type="regex" scope="text" nonoise="on" format="<b>$pattern(^\-\-\-\+*?\s([^\n\r]*).*)</b>"}%" else="<b>%TOPICNAME%</b>"}%</a>

If I understand correctly is supposed to target that which is under the first H1 heading on the page, but doesnt seem to work.

The second line of code, just appears on the page, and doesnt render any output. format="$percntCALC{$SET(title, $pattern(^\-\-\-\+*?\s([^\n\r]*).*))$IF($EXACT(, $TRANSLATE($GET(title), $comma, ;), %TOPICNAME%, $GET(title))}$percnt"

-- DanielBeaulieu - 2009-12-22

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2009-12-22 - DanielBeaulieu
 
  • 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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.