From 027c62bb51f8e6e29eedd2ada5f1b1f2cf2c743d Mon Sep 17 00:00:00 2001 From: Dreytac Date: Fri, 17 Apr 2026 03:14:17 +1000 Subject: [PATCH] Create KirbyTag. --- README.md | 16 ++++++++++++++++ index.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 9854ab6..e5fd3e2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,22 @@ A plugin for [Kirby](https://getkirby.com) to load the [Font Awesome](https://fontawesome.com) assets via the `getAssets()` hook of the [Kirby Library](https://git.hobbyhome.net/HobbyHome/kirby-library) plugin. +## KirbyTag + +``` + "regular"]) ?> + + +``` + +Supports the following attributes: + +- **style** - Inline CSS style to apply to the icon. +- **class** - CSS classes to apply to the icon. +- **family** - The Font Awesome family of icon. Defaults to `classic`. +- **fastyle** - The Font Awesome style of icon. Defaults to `solid`. +- **title** - A title to add to the icon. Useful for tooltips. + # License Kirby Font Awesome is Copyright 2026, [Dreytac](mailto:dreytac@hobbyhome.net). diff --git a/index.php b/index.php index f35076c..8f98d69 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,8 @@ Kirby::plugin( name: "hobbyhome/fontawesome", extends: [ "options" => [ + "defaultFamily" => "classic", + "defaultStyle" => "solid", "assets" => [ "css" => [ 150 => Url::path(kirby()->url("media") . "/plugins/hobbyhome/fontawesome/css/fontawesome" . r(!option("debug"), ".min") . ".css", true), @@ -43,6 +45,40 @@ Kirby::plugin( return $files; }, ], + "tags" => [ + "fa" => [ + "attr" => [ + "style", + "class", + "family", + "fastyle", + "title", + ], + "html" => function ($tag) { + $html = ""; + + if ($tag->style) { + $html .= "style}\">"; + } + + $html .= "class, $tag->class . " ") . + "fa-" . r($tag->family, $tag->family, option("hobbyhome.fontawesome.defaultFamily")) . " " . + "fa-" . r($tag->fastyle, $tag->fastyle, option("hobbyhome.fontawesome.defaultStyle")) . " " . + "fa-" . $tag->value . + "\"" . + r($tag->title, " title=\"{$tag->title}\"") . + ">"; + + if ($tag->style) { + $html .= ""; + } + + return $html; + }, + ], + ], ], info: [ "authors" => [[