You are here

function template_preprocess_uikit_card in UIkit Components 8.3

Prepares variables for UIkit Card templates.

Default template: uikit-card.html.twig.

Parameters

$variables: An associative array containing:

  • element: An associative array containing:

    • #content: The content of the article.
    • #title (optional): The title of the card.
    • #style (optional): The style of the card. Defaults to "default".
    • #hover (optional): Add hover effect to card. Defaults to FALSE.
    • #size (optional): The padding to apply to the card.
    • #badge (optional): The badge to apply to the card.
    • #header (optional): The heading to add to the card.
    • #footer (optional): The footer to add to the card.
    • #media (optional): An associative array containing:
      • alignment: Where the media is aligned in the card. Possible values are top or bottom. Left and right alignment is not currently available.
      • image_url: The URL for the image to display in the card.

If #media is set, #header and #footer will be ignored. This prevents the layout from being disrupted when #media is set. Since left and right media layouts are too complex, left and right alignment values are currently unavailable. See the documentation link below for more information.

See also

\Drupal\uikit_components\Element\UIkitCard

https://getuikit.com/docs/card

Related topics

File

includes/preprocess.inc, line 263
Set up variables to be placed within the template (.html.twig) files.

Code

function template_preprocess_uikit_card(&$variables) {
  $element = $variables['element'];

  // Set the title, content, badge, header, footer and media variables, if they
  // are not empty.
  if (!empty($element['#title'])) {
    $variables['title'] = $element['#title'];
  }
  if (!empty($element['#content'])) {
    $variables['content'] = $element['#content'];
  }
  if (!empty($element['#badge'])) {
    $variables['badge'] = $element['#badge'];
  }
  if (!empty($element['#header'])) {
    $variables['header'] = $element['#header'];
  }
  if (!empty($element['#footer'])) {
    $variables['footer'] = $element['#footer'];
  }
  if (!empty($element['#media'])) {
    $variables['media'] = $element['#media'];
  }

  // Set the attributes variable.
  $variables['attributes'] = $element['#attributes'];
}