Re: finding occurrences of symbols in a string

Petko Yotov <[email protected]>
Newsgroups gmane.comp.web.wiki.pmwiki.user
Message-ID <[email protected]>
In this case it may be simplest to redefine the $Title page variable.

You can have a custom function that intercepts any request for $Title, 
{*$Title}, {=$Title}, [[Some-Link|+]] and that examines the situation. 
If your conditions match, it calculates the response, otherwise it 
delegates to the core FmtPageTitle() function.

Something like this:

   $FmtPV['$Title'] = 'MyFmtPageTitle(@$page["title"], $group, $name)';

   function MyFmtPageTitle($title, $group, $name) {
     # existing (:title ...:) directive in page wins
     if($title>'') return $title;

     # we only enable our function in these wikigroups
     if($group == 'MyGroup' || $group == 'MyOtherGroup') {
       $name_parts = explode('-', $name);

       # and only when there are 1+ dashes in page name
       if(count($name_parts)>=2) {

         # return the last part
         return array_pop($name_parts);
       }
     }

     # otherwise defer to core
     return FmtPageTitle($title, $name, 0);
   }

If you enable this function, you don't need a (:title...:) directive in 
the general case where the function can handle it. If you have such a 
directive, the title defined in the directive will apply.

Note that some skins use the $Titlespaced variable instead of $Title, 
and see the documentation for $EnableLinkPlusTitlespaced. To redefine 
this "spaced" page variable, set $FmtPV['$Titlespaced'], and to defer to 
the core handler, call FmtPageTitle($title, $name, 1);

Petko



On 08/06/2023 22:54, Thomas Hirtenlehner wrote:
> Hi folks!
> 
> I tried to get some order into my pages by a naming scheme that sorts
> the pages in my glossary in an alphabetical order. So something like
> this:
> 
> mygroup.foo1-bar1
> mygroup.foo1-bar2
> mygroup.foo2-bar3-foobar1
> mygroup.foo2-bar3-foobar2
> 
> now foo1-bar2 is a rather lousy title for a page, so I tried to
> automate the title by excluding foo1 from the title like this:
> 
> (:title {(substr {$Name} 13)}:)
> 
> but of course, the 13 only works iff foo1 actually has 13 letters.
> 
> Is there a way to search for "-" to feed the substring directive
> automatically with the correct number?
> 
> and if so: how do I handle cases with more than one "-" in it?
> 
> thanks in advance!
> Thomas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.