Tags:
create new tag
view all tags

SID-02195: Accessing a users FirstName and LastName etc

Status: Answered Answered TWiki version: 4.1.2 Perl version: Perl 5.6.8
Category: CategoryAutomation Server OS: Sles Last update: 7 years ago

I am trying to create twiki pages describing how to set up git for our users. I wish to show an example of the commands users need to enter on a command line:

<tt>
git config --global user.name "John Doe" <br />
git config --global user.email johndoe@example.com<br />
</tt>

However I wished to provide a better example and knew from observation that the wiki knew the email and firstname and lastname of the person viewing the page. I felt I could do a far better job. So after playing about I ended up with:

<tt>
git config --global "%USERINFO{ format="$wikiname" }%"<br />
git config --global user.email "%USERNAME%"<br />
</tt>

However, the wikiname is missing a space between the first and last names also the I am getting a fair amount of push back from developers in that the syntax for these two trivial substitutions is so different the whole whole idea is being dismissed as unsupportable. Is there a better, more consistent way of doing the the above that allows me to make use of the "FirstName" and "LastName" fields that exist on each users home page?

-- fergus mcmenemie - 2016-05-03

Discussion and Answer

The TWiki variable SPACEOUT is your friend:

  • Type git config --global user.email "TWiki Guest"
  • Get git config --global user.email "TWiki Guest"

Also check out USERINFO with the $email formatting token, but note that often Mail addresses aren't exposed to the public.

-- Harald Jörg - 2016-05-03

Thanks Harald.

SPACEOUT only half worked and did not really address my question. Is there any clean consistent way of accessing the "FirstName" and other VARIABLES on my account page?

I suspect some kind of search might do it, but I understand the docs.

-- fergus mcmenemie - 2016-05-04

Ah, sorry for my lazy reading.

For accessing individual fields, use the FORMFIELD variable.

   * First name: %FORMFIELD{"FirstName" topic="%USERSWEB%.%WIKINAME%"}%
   * Last name: %FORMFIELD{"LastName" topic="%USERSWEB%.%WIKINAME%"}% 
   * Email: %FORMFIELD{"Email" topic="%USERSWEB%.%WIKINAME%"}% 

Expands to:

  • First name:
  • Last name:
  • Email:

-- Harald Jörg - 2016-05-05

Thanks very much. That is a fantastic general purpose solution.

I suspect this is quite a common requirement, so I am going to suggest it be added to the examples on the VarUSERINFO page. SPACEOUT etc just dont cut it with a name such as McMenemie.

The only remaining niggle is that writing "Last name: %FORMFIELD{"LastName" topic="%USERSWEB%.%WIKINAME%"}%" ends up being rendered as "McMenemie ?" and trying "Last name: !%FORMFIELD{"LastName" topic="%USERSWEB%.%WIKINAME%"}%" fails. (spot the ! smile

Is there a work around for this?

-- fergus mcmenemie - 2016-05-12

An alternative to VarSPACEOUT is $PROPERSPACE() of the SpreadSheetPlugin. The latter allows you to define exceptions to spacing out words with a DONTSPACE TWiki Preferences setting.

-- Peter Thoeny - 2016-05-13

About that remaining niggle: Yes, there's a workaround, or I'd even dare to say there's a solution for that problem. You just need to move the ! to the right spot. To that end, the FORMFIELD variable has a format parameter, which can in your case been used like this:

   * %FORMFIELD{"LastName" topic="%USERSWEB%.%WIKINAME%" format="!$value"}% 

But since we know that almost all assumptions about names are wrong you might want to accommodate for last names which have more than one word. Since I consider autolinking last names to be a bad idea, I'd be tempted to write:

   * %FORMFIELD{"LastName" topic="%USERSWEB%.%WIKINAME%" format="<noautolink>$value</noautolink>"}% 

Note that noautolink isn't a HTML element, it is a TWiki processing instruction, and it stacks properly if you nest noautolink sections.

-- Harald Jörg - 2016-05-13

      Change status to:
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.
SupportForm
Status Answered
Title Accessing a users FirstName and LastName etc
SupportCategory CategoryAutomation
TWiki version 4.1.2
Server OS Sles
Web server Apache 2.2
Perl version Perl 5.6.8
Browser & version any
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2016-05-13 - HaraldJoerg
 
  • 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.