Hi,
I want to display icons from Font Awesome in website texts, for that I made a kirbytag “icon”.
So for example, when I put (icon: arrow-circle-right)
in a textarea field that work just fine and give me this in the fronted:
<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>
But now i’m wondering what is the best way to do this with a kirbytag link.
I use Kirby Enhanced Textarea plugin and I manage to do this to choose a icon :
And that wrote this in the textarea field :
(link: http://www.url.com icon: arrow-circle-o-right text: some text popup: yes)
The output that I hope to get with it is :
<a href="http://www.url.com" target="_blank">
<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>some text
</a>
But I have no clue how to achieve it
Thanks if you can help !
I just test this :
[(icon: arrow-circle-right)some text](http://www.url.com)
This output what I want except for the target="_blank"
If you want to make an icon attribute work within the link tag, you have to copy and enhance the native link tag. The native link tag does not come with an icon attribute:
// link tag
kirbytext::$tags['link'] = array(
'attr' => array(
'text',
'class',
'role',
'title',
'rel',
'lang',
'target',
'popup'
),
'html' => function($tag) {
$link = url($tag->attr('link'), $tag->attr('lang'));
$text = $tag->attr('text');
if(empty($text)) {
$text = $link;
}
if(str::isURL($text)) {
$text = url::short($text);
}
return html::a($link, $text, array(
'rel' => $tag->attr('rel'),
'class' => $tag->attr('class'),
'role' => $tag->attr('role'),
'title' => $tag->attr('title'),
'target' => $tag->target(),
));
}
);
1 Like
Ok thank you for the hint !
I will try that
Copy the snippet above and save in /site/tags
as link.php. That way you can overwrite the existing tag.
1 Like