Jump to content

Template:CS button: Difference between revisions

From Insurer Brain
Content deleted Content added
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<templatestyles src="CS button/styles.css" />
<templatestyles src="CS button/styles.css"/>
<div class="capsach-align capsach-align-{{#switch:{{lc:{{{align|left}}}}}|center=center|right=right|left=left|#default=left}}">
<div class="capsach-align capsach-align-{{#switch:{{lc:{{{align|left}}}}}|center=center|right=right|left=left|#default=left}}">
{{#if:{{{link|}}}
{{#if:{{{link|}}}
|<span class="{{#switch:{{lc:{{{mobile|}}}}}
| [[{{{link}}}|<span class="capsach-btn" style="--cs-btn-width: {{{width|278px}}};" title="{{{tooltip|}}}">{{{text|Button}}}</span>]]
| full=capsach-btn capsach-btn--mobile
| {{#if:{{{url|}}}
| yes=capsach-btn capsach-btn--mobile
| [{{{url}}} <span class="capsach-btn" style="--cs-btn-width: {{{width|278px}}};" title="{{{tooltip|}}}">{{{text|Button}}}</span>]
| true=capsach-btn capsach-btn--mobile
| <span class="capsach-btn" style="--cs-btn-width: {{{width|278px}}};" title="{{{tooltip|}}}">{{{text|Button}}}</span>
| 1=capsach-btn capsach-btn--mobile
}}
| block=capsach-btn capsach-btn--mobile
| #default=capsach-btn}}"{{#if:{{{width|}}}| style="width: {{{width}}};"}}>
[[{{{link}}}|{{{text|Button}}}]]
</span>
|{{#if:{{{url|}}}
|<span class="{{#switch:{{lc:{{{mobile|}}}}}
| full=capsach-btn capsach-btn--mobile
| yes=capsach-btn capsach-btn--mobile
| true=capsach-btn capsach-btn--mobile
| 1=capsach-btn capsach-btn--mobile
| block=capsach-btn capsach-btn--mobile
| #default=capsach-btn}}"{{#if:{{{width|}}}| style="width: {{{width}}};"}}>
[{{{url}}} {{{text|Button}}}]
</span>
|<span class="{{#switch:{{lc:{{{mobile|}}}}}
| full=capsach-btn capsach-btn--mobile
| yes=capsach-btn capsach-btn--mobile
| true=capsach-btn capsach-btn--mobile
| 1=capsach-btn capsach-btn--mobile
| block=capsach-btn capsach-btn--mobile
| #default=capsach-btn}}"{{#if:{{{width|}}}| style="width: {{{width}}};"}}>
<span class="capsach-btn__inner" role="button" tabindex="0">{{{text|Button}}}</span>
</span>
}}
}}
}}
</div>
</div><noinclude>
== What this does ==
Renders a link styled as a '''button''' using TemplateStyles (loaded from ''CS button/styles.css'').
Supports alignment (left/center/right), an optional '''mobile full-width''' mode, and an optional custom '''width''' on desktop.
If neither <code>link</code> nor <code>url</code> is provided, the template outputs a non-link, button-like span as a visual fallback.

== Parameters ==
* <code>link</code> – Optional. Internal page to link to (e.g., <code>CS/Self-help book summaries</code>). If present, it takes precedence over <code>url</code>.
* <code>url</code> – Optional. Absolute URL for external destinations (e.g., <code>https://example.com</code>).
* <code>text</code> – Optional. Button label. Default: <code>Button</code>.
You can include symbols, e.g., <code>See more &amp;gt;</code> to show a single chevron.
* <code>align</code> – Optional. One of <code>left</code> (default), <code>center</code>, <code>right</code>. Controls the container alignment.
* <code>mobile</code> – Optional. When set to <code>full</code>, <code>yes</code>, <code>true</code>, <code>1</code>, or <code>block</code>, the button becomes 100% width on small screens (per the stylesheet’s media query).
* <code>width</code> – Optional. Desktop width of the button wrapper (e.g., <code>320px</code>, <code>24em</code>, <code>60%</code>). Defaults to the stylesheet’s width (278px).
On mobile, if <code>mobile=full</code> is used, the mobile rule overrides to full width.

== Examples ==
Basic (internal link):
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more
}}
</pre>

External link:
<pre>
{{CS button
| url=https://example.com/self-help
| text=Browse self-help
}}
</pre>

Center aligned:
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more
| align=center
}}
</pre>

Mobile full-width (desktop uses default width):
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more
| mobile=full
}}
</pre>

Wider on desktop (still full on mobile):
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more
| width=320px
| mobile=full
}}
</pre>

Percentage width on desktop:
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more
| width=60%
}}
</pre>

Non-link fallback (no navigation):
<pre>
{{CS button
| text=Coming soon
}}
</pre>

Add a chevron (arrow) to the label:
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=See more &gt;
}}
</pre>

Combine alignment, width, and mobile:
<pre>
{{CS button
| link=CS/Self-help book summaries
| text=Explore summaries &gt;
| align=right
| width=320px
| mobile=full
}}
</pre>

== Notes ==
* Use '''either''' <code>link</code> (internal) '''or''' <code>url</code> (external). If both are given, <code>link</code> wins.
* TemplateStyles must be available at <code>CS button/styles.css</code>.
* The template relies on ParserFunctions (<code>#if</code>, <code>#switch</code>, <code>lc</code>). Ensure that extension is enabled.
* Keep template calls flush-left (avoid leading spaces) to prevent MediaWiki from rendering a preformatted block around the output.

== Troubleshooting ==
* '''I see a big grey box / monospace text.''' You likely started a line with a space, which triggers preformatted output. Remove leading spaces and purge the page.
* '''Styles aren’t applying.''' Check that the stylesheet page uses the “Sanitized CSS” content model and that <code>&lt;templatestyles src="CS button/styles.css"/&gt;</code> is present at the top.
* '''Mobile full-width doesn’t activate.''' Confirm <code>mobile=full</code> (or accepted synonyms) and that your viewport is under the stylesheet’s breakpoint.
</noinclude>

Latest revision as of 14:00, 13 October 2025

Button

What this does

Renders a link styled as a button using TemplateStyles (loaded from CS button/styles.css). Supports alignment (left/center/right), an optional mobile full-width mode, and an optional custom width on desktop. If neither link nor url is provided, the template outputs a non-link, button-like span as a visual fallback.

Parameters

  • link – Optional. Internal page to link to (e.g., CS/Self-help book summaries). If present, it takes precedence over url.
  • url – Optional. Absolute URL for external destinations (e.g., https://example.com).
  • text – Optional. Button label. Default: Button.
 You can include symbols, e.g., See more &gt; to show a single chevron.
  • align – Optional. One of left (default), center, right. Controls the container alignment.
  • mobile – Optional. When set to full, yes, true, 1, or block, the button becomes 100% width on small screens (per the stylesheet’s media query).
  • width – Optional. Desktop width of the button wrapper (e.g., 320px, 24em, 60%). Defaults to the stylesheet’s width (278px).
 On mobile, if mobile=full is used, the mobile rule overrides to full width.

Examples

Basic (internal link):

{{CS button
 | link=CS/Self-help book summaries
 | text=See more
}}

External link:

{{CS button
 | url=https://example.com/self-help
 | text=Browse self-help
}}

Center aligned:

{{CS button
 | link=CS/Self-help book summaries
 | text=See more
 | align=center
}}

Mobile full-width (desktop uses default width):

{{CS button
 | link=CS/Self-help book summaries
 | text=See more
 | mobile=full
}}

Wider on desktop (still full on mobile):

{{CS button
 | link=CS/Self-help book summaries
 | text=See more
 | width=320px
 | mobile=full
}}

Percentage width on desktop:

{{CS button
 | link=CS/Self-help book summaries
 | text=See more
 | width=60%
}}

Non-link fallback (no navigation):

{{CS button
 | text=Coming soon
}}

Add a chevron (arrow) to the label:

{{CS button
 | link=CS/Self-help book summaries
 | text=See more >
}}

Combine alignment, width, and mobile:

{{CS button
 | link=CS/Self-help book summaries
 | text=Explore summaries >
 | align=right
 | width=320px
 | mobile=full
}}

Notes

  • Use either link (internal) or url (external). If both are given, link wins.
  • TemplateStyles must be available at CS button/styles.css.
  • The template relies on ParserFunctions (#if, #switch, lc). Ensure that extension is enabled.
  • Keep template calls flush-left (avoid leading spaces) to prevent MediaWiki from rendering a preformatted block around the output.

Troubleshooting

  • I see a big grey box / monospace text. You likely started a line with a space, which triggers preformatted output. Remove leading spaces and purge the page.
  • Styles aren’t applying. Check that the stylesheet page uses the “Sanitized CSS” content model and that <templatestyles src="CS button/styles.css"/> is present at the top.
  • Mobile full-width doesn’t activate. Confirm mobile=full (or accepted synonyms) and that your viewport is under the stylesheet’s breakpoint.