Difference between revisions of "Template:NameSorter"

From ChoralWiki
Jump to navigation Jump to search
(ucfirst: to guarantee that the first letter is uppercase)
(using LastNameFirst)
Line 1: Line 1:
<includeonly>{{#ifexpr: {{#len:{{#explode:{{{1|{{PAGENAME}}}}}||-1}}}} = {{#len:{{{1|{{PAGENAME}}}}}}}
+
<includeonly>{{StripAccents|{{LastNameFirst|{{{1|{{PAGENAME}} }}} }} }}</includeonly><noinclude><!--
|{{ucfirst:{{StripAccents|{{{1|{{PAGENAME}}}}} }} }}
 
|{{ucfirst:{{StripAccents|{{#explode:{{{1|{{PAGENAME}}}}}||-1}}, {{#sub:{{{1|{{PAGENAME}}}}}||{{#expr:{{#len:{{{1|{{PAGENAME}}}}}}} - {{#len:{{#explode:{{{1|{{PAGENAME}}}}}||-1}}}} }} }} }} }}
 
}}</includeonly><noinclude><!--
 
 
-->{{DisplayBox|bgcolor=g|text=
 
-->{{DisplayBox|bgcolor=g|text=
 
Converts a text in the form "Name(s) Surname" to the form "Surname, Name(s)", removing all diacritics in the process.
 
Converts a text in the form "Name(s) Surname" to the form "Surname, Name(s)", removing all diacritics in the process.
Line 21: Line 18:
 
* <tt><nowiki>{{DEFAULTSORT:La Rue, Pierre de}}</nowiki></tt>
 
* <tt><nowiki>{{DEFAULTSORT:La Rue, Pierre de}}</nowiki></tt>
 
}}
 
}}
[[Category:Templates|{{PAGENAME}}]]
+
[[Category:Text formatting templates]]
 
</noinclude>
 
</noinclude>

Revision as of 05:20, 10 March 2013

Converts a text in the form "Name(s) Surname" to the form "Surname, Name(s)", removing all diacritics in the process.

Syntax:

  • {{NameSorter}} returns the contents of {{PAGENAME}} after processing it.

Syntax with an optional parameter:

  • {{NameSorter|Antonín Dvořák}} returns "Dvorak, Antonin "


This template is meant to be used in conjunction with the magic word DEFAULTSORT inside Composer and User pages, delivering to it an appropriate sort key.

  • {{DEFAULTSORT:{{NameSorter}}}}

In the cases in which the template returns an invalid sort key, as for example "Rue, Pierre de la", use a textual key instead:

  • {{DEFAULTSORT:La Rue, Pierre de}}