Template:LinkIcon: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
N (talk | contribs)
Added support for custom link colours
refactored the Link family
Line 1: Line 1:
<noinclude>
<includeonly><!--
This template is meant to handle the linking of articles in a way that is language-agnostic, meaning that it can be used in language-aware infoboxes and other contexts which need to be able to handle multiple languages. This template only works with concepts which have their translation managed by Cargo.
-->{{#cargo_query:
tables =
    Translation = E,
    Translation = T
|join on =
    E.target_id = T.target_id
|where =
    (E.target_id = '{{{id}}}' OR E.subtype = '{{{id}}}') <!-- TODO: why also subtype? -->
    {{#if:{{{type|}}} | AND E.type = '{{{type}}}' }}
    AND E.language = 'en'
    <!-- foreign language -->
    {{#if:{{{type|}}} | AND T.type = '{{{type}}}' }}
    {{#if:{{{lang|}}} | AND T.language = '{{{lang}}}' | AND T.language = 'en' }}
|fields =
    <!-- filename -->
    {{#switch: {{{filename|}}}
        |=CONCAT(E.target_id, "{{{suffix|.png}}}")=filename, <!-- automatic behavior -->
        |0=<!-- omitted filename -->
        |#default=CONCAT("{{{filename}}}")=filename, <!-- overridden filename -->
    }}
    <!-- link -->
    {{#switch: {{{link|}}}
        |=E.name=link, <!-- automatic behavior -->
        |0=<!-- intentionally empty parameter, omit the link -->
        |#default=CONCAT("{{{link}}}")=link, <!-- overridden link -->
    }}
    <!-- text -->
    {{#switch: {{{text|}}}
        |=T.name=text, <!-- automatic behavior -->
        |0=<!-- intentionally empty parameter, omit the name -->
        |#default=CONCAT("{{{text}}}")=text, <!-- overridden name -->
    }}
    T.language = lang,
    {{#if:{{{size|}}} | CONCAT("{{{size}}}") = size }}
    {{#if:{{{color|}}} | CONCAT("{{{color}}}") = color }}
|format =
    template
|template =
    {{#switch: {{{stack|}}}
        |1=Link/stack
        |#default=Link/render
    }}
|named args =
    yes
|limit =
    1
|more results text =
}}<!--
################################################################################
--></includeonly><noinclude>


This template is meant to handle the linking of articles in a way that is language-agnostic, meaning that it can be used in language-aware infoboxes and other contexts which need to be able to handle multiple languages. This template only works with concepts which have their translation managed by Cargo.


<pre><nowiki>{{LinkIcon|type=faction|id=human|suffix=_icon.png}}</nowiki></pre>
The default assumption for the icon's file name is that it is identical to the {{b|id}}, plus the <code>.png</code> extension. This can be further configured with the {{b|suffix}} parameter, or be completely overridden by the {{b|filename}} parameter.
{{LinkIcon|type=faction|id=human|suffix=_icon.png}}


<pre><nowiki>{{LinkIcon|type=faction|id=human|suffix=_icon.png|lang=pl}}</nowiki></pre>
===Usage===
{{LinkIcon|type=faction|id=human|suffix=_icon.png|lang=pl}}


<pre><nowiki>{{LinkIcon|type=faction|id=human|suffix=_icon.png|size=64px|color=yellow}}</nowiki></pre>
1. Basic (rarely used, as you usually need to specify {{b|type}} and {{b|suffix}}):
{{LinkIcon|type=faction|id=human|suffix=_icon.png|size=64px|color=yellow}}


</noinclude><includeonly>{{#cargo_query:
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon}}</nowiki></code>
tables  = Translation=T_en, Translation=T_disp
 
|join on = T_en.target_id = T_disp.target_id
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon}}
|where  = (T_en.target_id  = '{{{id}}}' OR T_en.subtype = '{{{id}}}')
 
          AND T_en.type    = '{{{type}}}'  AND T_en.language  = 'en'
----
          AND T_disp.type = '{{{type}}}'  AND T_disp.language = '{{{lang|en}}}'
 
|fields  = T_en.name = link, T_disp.name = text, T_disp.language = lang, CONCAT('{{{prefix|}}}', T_en.target_id,'{{{suffix|.png}}}') = filename, {{#if:{{{size|}}} | CONCAT('{{{size}}}') = size }}, {{#if:{{{color|}}} | CONCAT('{{{color}}}') = color }}
2. With {{b|type}}:
|format  = template
 
|template= Link/render
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=skill_assault | type=skill}}</nowiki></code>
|named args = yes
 
|limit  = 1
{{Color|lime|Output:}} {{LinkIcon | id=skill_assault | type=skill}}
|more results text=
 
}}</includeonly>
----
 
3. With {{b|suffix}}, to override the default (<code>.png</code>):
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=angel | suffix=_icon.png}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=angel | suffix=_icon.png}}
 
----
 
4. With {{b|lang}}, to override the default (<code>en</code>):
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon || lang=ja}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon || lang=ja}}
 
----
 
5. With {{b|size}}, to override the default (<code>32px</code>):
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | size=64px}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | size=64px}}
 
----
 
6. With {{b|filename}}, to override the automated file path:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=human_hero_1 | type=hero | filename=Ister.png}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=human_hero_1 | type=hero | filename=Ister.png}}
 
----
 
7. With {{b|zero filename}}, to disable the icon:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | filename=0}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | filename=0}}
 
----
 
8. With {{b|text}}, to override the automated text:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | text=Hello}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | text=Hello}}
 
----
 
9. With {{b|zero text}}, to disable the text:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | text=0}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | text=0}}
 
----
 
10. With {{b|link}}, to override the automated link:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | link=Foobar}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | link=Foobar}}
 
----
 
11. With {{b|zero link}}, to disable the link:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | link=0}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | link=0}}
 
----
 
12. With {{b|color}}:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | color=magenta}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | color=magenta}}
 
----
 
13. With {{b|1=stack=1}}, to switch to a vertical layout:
 
{{Color|yellow|Input:}} <code><nowiki>{{LinkIcon | id=magic_demon | stack=1}}</nowiki></code>
 
{{Color|lime|Output:}} {{LinkIcon | id=magic_demon | stack=1}}
 
</noinclude>

Revision as of 13:07, 26 June 2026


This template is meant to handle the linking of articles in a way that is language-agnostic, meaning that it can be used in language-aware infoboxes and other contexts which need to be able to handle multiple languages. This template only works with concepts which have their translation managed by Cargo.

The default assumption for the icon's file name is that it is identical to the id, plus the .png extension. This can be further configured with the suffix parameter, or be completely overridden by the filename parameter.

Usage

1. Basic (rarely used, as you usually need to specify type and suffix):

Input: {{LinkIcon | id=magic_demon}}

Output: Herald


2. With type:

Input: {{LinkIcon | id=skill_assault | type=skill}}

Output: Offense


3. With suffix, to override the default (.png):

Input: {{LinkIcon | id=angel | suffix=_icon.png}}

Output: Angel


4. With lang, to override the default (en):

Input: {{LinkIcon | id=magic_demon || lang=ja}}

Output: ヘラルド


5. With size, to override the default (32px):

Input: {{LinkIcon | id=magic_demon | size=64px}}

Output: Herald


6. With filename, to override the automated file path:

Input: {{LinkIcon | id=human_hero_1 | type=hero | filename=Ister.png}}

Output: Ister


7. With zero filename, to disable the icon:

Input: {{LinkIcon | id=magic_demon | filename=0}}

Output: Herald


8. With text, to override the automated text:

Input: {{LinkIcon | id=magic_demon | text=Hello}}

Output: Hello


9. With zero text, to disable the text:

Input: {{LinkIcon | id=magic_demon | text=0}}

Output:


10. With link, to override the automated link:

Input: {{LinkIcon | id=magic_demon | link=Foobar}}

Output: Herald


11. With zero link, to disable the link:

Input: {{LinkIcon | id=magic_demon | link=0}}

Output: Herald


12. With color:

Input: {{LinkIcon | id=magic_demon | color=magenta}}

Output: Herald


13. With stack=1, to switch to a vertical layout:

Input: {{LinkIcon | id=magic_demon | stack=1}}

Output: Herald