Closed chrfickinger closed 4 years ago
Oh, it does this on empty icons. I'm not sure how it should handle those.
Maybe the Kirby "files field approach", where "toFile" returns a falsy value when there is no file selected. This would mean that we need to write the template like this:
<?php if($icon = $page->myIcon()->toIcon() ?>
<?= $icon->use() ?>
<?php ?>
Or, it could simply fail silently and not output anything. Don't know what's more desirable. What do you think?
I have also tried your suggestion, but it does not help.I still get the same error.
Probably it's because toIcon()
only works for $page
and not also for $item
?
yeah that isn't implemented - I was just pondering about the question if empty fields should just fail silently if there is no icon, or if it should return null like the toFile method does.
The latest version does now fail silently (empty or faulty icons simply don't output anything). So you should just need to download the latest version as zip.
toIcon is called on a field, if that field is on $item, $page, $site or anything other doesn't change. :)
yeah that isn't implemented - I was just pondering about the question if empty fields should just fail silently if there is no icon, or if it should return null like the toFile method does.
I don't know what's better, null like the toFile method is probably a good choice. An additional fallback icon would also be a good option.
Latest version now includes a fallback option if the icon is empty or in an invalid format. Use it like this:
$page->shareIcon()->toIcon('fal fa-share-alt')->use();
'fal fa-share-alt'
being the fallback.
you can also check if an icon is invalid:
<?php if($page->shareIcon()->toIcon()->isInvalid()): ?>
Icon is invalid!
<?php endif; ?>
toIcon()
works only for$page
e.g.
$page->icon()->toIcon()->use());
if you use icons for your navigation, the funciotn throws an error
e.g.
$items = $pages->listed();
foreach($items as $item):
echo $item->icon()->toIcon()->use());
endif;