Template:Path stripper Dave

From Wikisphere
Jump to navigation Jump to search

see here https://sourceforge.net/p/semediawiki/mailman/semediawiki-user/?viewmonth=202107 (Dave)


I figured it out.… to close the loop, I’m offering my solution. Not because I think this is better/easier that your extension, but just because I wanted to learn how (as this may solve other issue).

Assuming I have a {PATH} = /Animals/Pets/Dogs/
And 3 articles under it = Snoopy, Goofy, Toto

For the query: {{#ask: [[Category: {PATH} }}
I’m getting back full path names in #ask:  [[{{FULLPAGENAME}}|FULLPAGENAME}}]]

The default result was:
[[/Animals/Pets/Dogs/Snoopy|/Animals/Pets/Dogs/Snoopy]]
[[/Animals/Pets/Dogs/Goofy |/Animals/Pets/Dogs/Goofy]]
[[/Animals/Pets/Dogs/Toto |/Animals/Pets/Dogs/Toto]]

And what I want it in the [[ {{FULLPAGENAME}} | {{SUBPAGENAME}} ]] (comma delimited)— without installing extensions, etc.

So here’s my hack… er solution.

This query will get a list of links for all things in the Category {PATH} and pass them to the template Path_Stripper

{{#ask: [[Category: {PATH} ]]
| ?=
| format=plainlist
| template=Path_Stripper
| userparam= {PATH}
| sep=, 
}}

The Template:Path_Stripper strips out the path (after the pipe character, and makes sure to return it) using the following:

{{#replace:{{{1|}}}|{{!}}{{{#userparam}}}|{{!}}}}

The new results were: [[/Animals/Pets/Dogs/Snoopy|Snoopy]], [[/Animals/Pets/Dogs/Goofy |Goofy]], [[/Animals/Pets/Dogs/Toto |Toto]]

Thanks again for offering a suggestion.

Dave