Help:Shortcode Alert

Display a alert box in the page.

Alert
Shortcode
Description
TypeHTML Shortcode
Nested?true
Shortcodealert
Return TypeHTML
Short Description
Display a message in a box. Either a predefined one, or written on the fly.
Development
MaintainerMichael Sasser

This kind of shortcode is called a “nested shortcode”. You can tell that it is nested because it actually consists of two shortcodes with “something” in the middle. It is just like HTML, where you have one tag (here shortcode), which defines the beginning of a scope and one the end. Like in HTML the closing tag uses the slash / before the designator to indicate an ending scope after this point.

Parameters

The post shortcode has the following parameters:

ParameterOptionalDescription
titleYesThe title of the alert
typeYes (defaults to primary)The type of the alert (see section below)
namedYesUse a predefined preset to set title, type (and “.Inner”)
.InnerWhen not using namedThe actual text

Types

Depending on the type, the color and symbol in the front changes. This should help the reader to understand the meaning of the alert. The type danger has a red signal color and a exclamation mark as symbol, which transmits a different priority and feeling than the success type, which green color and a checkmark as symbol.

The type parameter can be one of the following:

TypeDescription
primaryPrimary alert (default)
secondarySecondary alert
successSuccess alert
dangerDanger alert
warningWarning alert

Presets

Some alerts are used quite often throughout the website. For those we created presets that replace the title, context and type by predefined options. This allows us to change them from a single location.

PresetDescription
cocTell the user to read the Code of Contact before continuing
contrib-legalTell the user, that only content done by the user will be accepted in an merge request
todoTell the user, that this part of the website is not ready yet
license-codeTell the user, the source code is MIT licensed

Examples

The most simple alert is one without a title and type. When no type was set, the default type primary is used.

{{< alert >}}
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum
sint consectetur cupidatat.
{{< /alert >}}
Rendered
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

An example for an primary alert would be this:

{{< alert title="Primary" type="primary" >}}
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum
sint consectetur cupidatat.
{{< /alert >}}

In the rendered form it looks like the following.

Rendered

Primary

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Below, you see all types of alerts rendered. The title in those demo alerts matches the type in title-case.

Rendered

Primary

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Secondary

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Success

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Danger

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Warning

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

Presets are rendered like this:

{{< alert preset="coc" >}}{{< /alert >}}
{{< alert preset="contrib-legal" >}}{{< /alert >}}
{{< alert preset="todo" >}}{{< /alert >}}
{{< alert preset="license-code" >}}{{< /alert >}}
Rendered
Before you continue, make sure to read our Code of Conduct.

Legal Warning

Every text and image you use must have been created or written by yourself!

By creating a Pull Request, you agree that the image or text may be used without any restriction for community projects under the direction of the moderation team at any time.

Non-compliance may have legal consequences and can lead to immediate exclusion from the community.

Coming Soon

This part of our new Website is not ready yet.

raise NotImplementedError("Stay Tuned")
This code is licensed under the MIT license.

Code

Below you find the implementation of the shortcode.

HTML

Defined in layouts/shortcodes/alert.html.

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

  Alert Shortcode
  ===============

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

  LAYOUT: /layouts/shortcodes/alert.html
  STYLE:  /assets/scss/components/_shortcode_alert.scss
  DOCS:   /content/<language>/wiki/Help:Shortcode_Alert.md

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

  Use the alert shortcode to display a message in a box. Either a predefined
  one, or one, which is written on the fly. 

  Changelog
  =========

  Version 1
  ---------

  Initial release

  Version 2 (2020-07-16)
  ----------------------

  Rewrite to merge the different types into a single shortcode

-->

{{ $type := .Get "type" | default "primary" }}
{{ $title := .Get "title" | default "" }}
{{ $preset := .Get "preset" | default "" }}

{{ $content := "" }}

{{ if $preset }}
  {{ if eq $preset "contrib-legal" }}
    {{ $type = "warning" }}
    {{ $title = i18n "alert-contrib-legal-title" }}
    {{ $content = i18n "alert-contrib-legal-content" }}
  {{ else if eq $preset "coc" }}
    {{ $type = "success" }}
    {{ $content = printf "%s <a href=\"%s\">%s</a>." (i18n "alert-coc-content") (relref . "/docs/code_of_conduct") (i18n "coc") }}
  {{ else if eq $preset "license-code" }}
    {{ $type = "success" }}
    {{ $content = printf "%s <a href=\"%s/blob/%s/LICENSE.md\" target=\"_blank\" rel=\"noopener\">MIT %s</a>." (i18n "alert-license-code-content") .Site.Params.docsRepo .Site.Params.docsRepoBranch (i18n "license")}}
  {{ else if eq $preset "todo" }}
    {{ $title = "Coming Soon"}}
    {{ $content = "This part of our new Website is not ready yet.<br /><br /><code><span class=\"hljs-keyword\">raise</span> NotImplementedError(<span class=\"hljs-string\">\"Stay Tuned\"</span>)</code>" }}
  {{ else }}
    {{ errorf "Failed to process alert shortcode: %s. %q is unknown preset in \"alert\" shortcode. The available presets are: \"contrib-legal\", \"coc\", \"license-code\"  and \"todo\"." $.Position $type }}
  {{ end }}
{{ end }}

<div class="mp-alert mp-alert-{{ $type }}">
  <div class="icon">
    {{ if eq $type "primary"}}
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="mp-alert-svg mp-alert-primary-svg feather feather-alert-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
    {{ else if eq $type "success" }}
       <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="mp-alert-svg mp-alert-success-svg feather feather-check-circle"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>
    {{ else if eq $type "danger" }}    
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="mp-alert-svg mp-alert-danger-svg feather feather-alert-octagon"><polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"></polygon><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
    {{ else if eq $type "warning" }}
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="mp-alert-svg mp-alert-warning-svg feather feather-alert-triangle"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>
    {{ else if eq $type "secondary" }}
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="mp-alert-svg mp-alert-secondary-svg feather feather-alert-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>            
    {{ else }}
      {{ errorf "Failed to process alert shortcode: %s. %s is unknown type in \"alert\" shortcode. The available types are \"primary\", \"success\", \"alert\", \"danger\" and \"secondary\"." $.Position $type }}
    {{ end }}
  </div>
  <div class="content">
    {{ with $title }}      
        <p class="mp-alert-title">{{ . }}</p>
    {{ end }}
    <div class="body">
      {{ with $content }} 
        {{ print . | safeHTML }}
      {{ else }}
        {{ if len .Inner }}
          {{ print .Inner | markdownify }}
        {{ else }}
          {{ errorf "Failed to process alert shortcode: %s. When using the alert shortcode .Inner (the context of a nested statement) is mandatory, when the \"named\" argument is not used instead." $.Position }}
        {{ end }}
      {{ end }}
    </div>
  </div>
</div>

Download

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

  • Alert Shortcode
    alert.html4.71 KB
  • md5   147f3619048f1ab7ac341e0bbfadbb74
  • sha1   8408e679355d097680946d227579f9b9cade58b2
  • sha256   ecf90c166cde883eeb6c5442fb536bf64450c71cf3d7580f630e9809fa4bd524

SASS

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

This code is licensed under the MIT license.
/*

  Alert Shortcode
  ===============

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

  LAYOUT: /layouts/shortcodes/alert.html
  STYLE:  /assets/scss/components/_shortcode_alert.scss
  DOCS:   /content/<language>/wiki/Contribute:Shortcode_Download/index.md

*/

.mp-alert {
  border: 1px solid $gray-200;
  padding: 1rem;
  border-radius: 5px;
  display: flex;
  margin: 1em 0;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 50%);

  .content {
    padding-left: 1em;

    .mp-alert-title {
      font-size: 1.2rem;
      font-weight: bold;
      margin-bottom: 0.5em;
    }

    p {
      margin-bottom: 0;
    }

    br {
      display: block;
      margin-bottom: 0.25em;
      content: " ";
    }
  }
}

.mp-alert-primary {
  border-left: 5px solid $primary;
}

.mp-alert-success {
  border-left: 5px solid $success;
}

.mp-alert-danger {
  border-left: 5px solid $danger;
}

.mp-alert-warning {
  border-left: 5px solid $warning;
}

.mp-alert-secondary {
  border-left: 5px solid;
}

.mp-alert-svg {
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.mp-alert-primary-svg {
  stroke: $primary;
}

.mp-alert-success-svg {
  stroke: $success;
}

.mp-alert-danger-svg {
  stroke: $danger;
}

.mp-alert-warning-svg {
  stroke: $warning;
}

.mp-alert-secondary-svg {
  stroke: $secondary;
}

@include color-mode(dark) {
  .mp-alert {
    border: 1px solid $border-dark;
  }

  .mp-alert-primary {
    border-left: 5px solid $primary;
  }

  .mp-alert-success {
    border-left: 5px solid $success;
  }

  .mp-alert-danger {
    border-left: 5px solid $danger;
  }

  .mp-alert-warning {
    border-left: 5px solid $warning;
  }

  .mp-alert-secondary {
    border-left: 5px solid $secondary;
  }
}

Download

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

  • Alert Style
    _shortcode_alert.scss1.82 KB
  • md5   be3e6d85ff6716c96a5d619896a95a46
  • sha1   425429b2db3c9a2e9efedd93cfa7030839fbdfad
  • sha256   d52355dcff8f8a4b86c6c6ff8d68cf2f6c40c116de9ba327c257da4137d8d3cc
Top