Documentation | This is a documentation subpage for Template:Link attributes (see that page for the template itself). It contains usage information, categories and other content that is not part of the original template page. |
Usage
{{link attributes}} applies CSS style and/or HTML attributes to a link. It accepts six parameters:
- the page being linked
- the style of the link - optional
- the style of the link if the page being linked does not exist - optional - only for intra-wiki links
text
- link text to show - optionalattribs
- extra HTML attributes to add - optionalext
- if present, the link is external
Link style
To change the style of a link:
[[Scratch Wiki]] vs. {{link attributes|Scratch Wiki|color:gray}}
Scratch Wiki vs. Template:Link attributes
Alternate link text style
To change the style of a link with custom link text:
[[Scratch Wiki|the Wiki]] vs. {{link attributes|Scratch Wiki|color:gray|text=the Wiki}}
the Wiki vs. Template:Link attributes
Note that you must specify text=
to have alternate link text.
Using an external link
To change whether it is an internal link or an external link:
[https://scratch.mit.edu/ Scratch] vs. {{link attributes|https://scratch.mit.edu/|color:gray|text=Scratch|ext=t}}
Scratch vs. Template:Link attributes
Note that you must specify ext=something
to have an external link. (The value need not be "t" or "something", as long as it's not empty)
Red link style
Template:Note To change the style of a link to a nonexistent page:
[[No page here]] vs. {{link attributes|No page here|color:gray|color:magenta}}
No page here vs. Template:Link attributes
Note that the style in the third parameter is applied, since the page does not exist.
Alternate red link text style
Template:Note To change the style of a link to a nonexistent page with custom link text:
[[No page here|Nope]] vs. {{link attributes|No page here|color:gray|color:magenta|text=Nope}}
Nope vs. Template:Link attributes
Here, four parameters are put into use. The first parameter is the page itself, the second is the style for the link, the third is the style if the page doesn't exist, and text
is the alternate text for the link.
Extra HTML attributes
To add a title
attribute to a link:
[[Scratch Wiki]] vs. {{link attributes|Scratch Wiki|attribs=title="Hi, this is a demonstration of the HTML title attribute!"}} (hover)
Scratch Wiki vs. Template:Link attributes (hover)
Here, the optional attribute title
is applied to the text.
All together now
To add a title
attribute and change the style of a link to a nonexistent page with custom link text:
[[No page here|Nope]] vs. {{link attributes|No page here|color:gray|color:magenta|text=Nope|attribs=title="You're not finding a page here!"}}
Nope vs. Template:Link attributes
And now to link to an external page:
[https://scratch.mit.edu/ Scratch] vs. {{link attributes|https://scratch.mit.edu/|color:gray|text=Scratch|attribs=title="hehe cool"|ext=t}}
Scratch vs. Template:Link attributes
Here, in these two examples five parameters are put into use. The first parameter is the link target, the second is the style, text
is the link text, ext
is to specify it as an external link, and attribs
is the extra HTML attributes for the link.