Help:Shortcode Badge

Create a badge.

Badge
Shortcode
Description
TypeHTML Shortcode
Nested?false
ShortcodeBadge
Return TypeHTML
Short Description
Display a Badge
Development
MaintainerMichael Sasser

Use the shortcode Badge to display a square, rounded or pill shaped box with a small title in it.

Parameters

The Badge shortcode has the following parameters:

ParameterDefaultDescription
title-The badge title or text.
shaperoundedThe shape of the badge. It can be rounded, square or pill shaped.
typeprimaryThe type of the badge, which sets it’s color. The type can be primary, secondary success, warning or danger.

Overview

The following matrix shows all possible options for the badge shortcode.

roundedsquarepill
primaryprimary, roundedprimary, squareprimary, pill
secondarysecondary, roundedsecondary, squaresecondary, pill
successsuccess, roundedsuccess, squaresuccess, pill
warningwarning, roundedwarning, squarewarning, pill
dangerdanger, roundeddanger, squaredanger, pill

Examples

{{< badge title="foo" shape="rounded" type="primary" >}}
{{< badge title="bar" >}}
Rendered
foo bar

Code

Below you find the implementation of the shortcode.

HTML

Defined in layouts/shortcodes/badge.html.

This code is licensed under the MIT license.
<!--

  Badge Shortcode
  ===============

  Contributors: Michael Sasser
  Maintainer: Michael Sasser
  License: MIT
  Version: 1
  Child Shortcodes: None
  Parent Shortcodes: None

  LAYOUT: /layouts/shortcodes/badge.html
  STYLE:  /assets/scss/components/_shortcode_badge.scss
  DOCS:   /content/<language>/wiki/Help:Shortcode_Badge.md

  Description
  -----------

  Create a badge.

  Changelog
  =========

  Version 1 (2022-11-17)
  ----------------------

  Initial release

-->

{{- $title := .Get "title" -}}
{{- $type := .Get "type" | default "primary" -}}
{{- $shape := .Get "shape" | default "rounded" -}}

{{- $types_possible := slice "primary" "secondary" "success" "danger" "warning" -}}
{{- $shapes_possible := slice "rounded" "square" "pill" -}}

{{- if not $title -}}
  {{- errorf "Failed to process badge shortcode: %s. The shortcode needs a title" $.Position -}}
{{- end -}}

{{- if not (in $types_possible $type) -}}
  {{- errorf "Failed to process badge shortcode: %s. Only %s are valid types." $.Position  (delimit ($types_possible) ", ") -}}
{{- end -}}

{{- if not (in $shapes_possible $shape) -}}
  {{- errorf "Failed to process badge shortcode: %s. Only %s are valid shapes." $.Position  (delimit ($shapes_possible) ", ") -}}
{{- end -}}


<span class="badge badge-{{- $type }} badge-{{- $shape }}">{{- $title -}}</span>

Download

Copy the source code above or use the download link below to use this file on your website according to the license.

  • Badge Shortcode
    badge.html1.35 KB
  • md5   5934e0ee44a93e9cd2eefc6d84a6eaf2
  • sha1   75a1cddcdea47eaf87d3bc841d9b4d497be76c3c
  • sha256   602691daa377769dcfd6d5a7f03370c14a5a2f32825e699ea3f8ebc87c14a7a2

SASS

Defined in: /assets/scss/components/_shortcode_badge.scss

This code is licensed under the MIT license.
/*
  Badge Shortcode
  ===============

  Contributors: Michael Sasser
  Maintainer: Michael Sasser
  License: MIT
  Version: 1
  Child Shortcodes: None
  Parent Shortcodes: None

  LAYOUT: /layouts/shortcodes/badge.html
  STYLE:  /assets/scss/components/_shortcode_badge.scss
  DOCS:   /content/<language>/wiki/Help:Shortcode_Badge.md

*/

/* Variants */
.badge-primary {
  color: darken($primary, 35%);
  background: lighten($primary, 30%);
}

.badge-secondary {
  color: darken($secondary, 40%);
  background: lighten($secondary, 45%);
}

.badge-danger {
  color: darken($danger, 35%);
  background: lighten($danger, 30%);
}

.badge-warning {
  color: darken($warning, 35%);
  background: lighten($warning, 30%);
}

.badge-success {
  color: darken($success, 20%);
  background: lighten($success, 30%);
}

/* Shapes */
.badge-rounded {
  border-radius: 3px;
}

.badge-pill {
  border-radius: 25px;
}

.badge-square {
  border-radius: 0;
}

Download

Copy the source code above or use the download link below to use this file on your website according to the license.

  • Badge Style
    _shortcode_badge.scss942.00 Bytes
  • md5   b1ad8edd4054b9f1d9400d80236a2842
  • sha1   9605bdffd7273ac2071ea42f6d17cf66f05d20ec
  • sha256   3268dc045fb2026baf1701edc67d229e956f125cf22dba9cd71427063d50bcd1
Top