Topic on Project:Support desk

Is it possible to have templates parse individual characters from a parameter?

5
AlexGRFan97 (talkcontribs)

To try and explain what I want, in the clearest manner possible:

I have a template, Song.

I have a parameter, songname.

I wish to alter the template so it will automatically take the first letter of the songname parameter (i.e. if the song's name is "Jessica", then it will take the "J", and that will allow me to create a sub-parameter that will then link to a page called "List of music featured in automotive journalism media/J", which will then have (#songname) appended to the end so it automatically jumps to the relevant song in that article.

Thanks in advance.

Bawolff (talkcontribs)
AlexGRFan97 (talkcontribs)

Right, the second option sounds good to me!

My only question how would I then use the substring as a parameter of its own once it's been generated?

So I'd imagine it would be set up like:

{{#sub:{{{songname}}}|1}} and that would get me the substring I seek without modifying the data already input. So if the songname variable was "Jessica", the "1" would denote it to sample only the J.

I would then append a link to [[List of music featured in automotive journalism media/{{{substringvarname}}}#{{{songname}}}]] in the template. If I'm right, it should just be a case of putting the "sub" template in the place of "substringvarname", but I could be wrong.

Bawolff (talkcontribs)

Yes

AlexGRFan97 (talkcontribs)

Right, that's sorted.

For future reference, in case anyone wants to do what I did, you need to use {{#sub:{{{songname}}}|0|1}}so it takes only the first letter of the phrase, as opposed to just "1" on its own, which takes away the first letter and leaves the rest of the string intact.

Solved!