Kirby Flags adds page methods and a panel field for multiple types of flags.
Forked from medienbaecker/kirby-likes for the core design and functionality.
Still includes 'like' ❤️ but also adds 'strike' ⛔, 'bell' 🔔, 'edit' 📝 and 'photo' 📷.
As a PHP string
<a href="<?= $page->url() ?>/flag/like/toggle">❤️</a>
or as Twig Template
<a href="{{ page.url() }}/flag/like">❤️</a>
Totally understandable if this part seems weird and hacky. Its for specific behavior needed in the Commutron CMS. In a different context where you don't need all that it works just fine if you ignore this part.
For use with 'medienbaecker/kirby-modules' plugin; the page URL needs to point to the module and a third parameter is required for redirect.
<a href="<?= page.parent.parent.url() ?> . '/modules/' . <?= page.slug ?> . '/flag/photo/ ' . <?= page.parent.parent.uri ?>">📷</a>
In addition it accepts URL content query strings and anchor/hash tags.
But to avoid the query strings from being stripped out; the ?
must be replaced with ~*~
.
<a href="<?= page.parent.parent.url() ?> . '/modules/' . <?= page.slug ?> . '/flag/photo/ ' . <?= page.parent.parent.uri ?> . '~*~m=' . <?= page.slug ?> . '#' . <?= page.slug ?>">📷</a>
<a href="{{ page.parent.parent.url() }}/modules/{{ page.slug }}/flag/edit/{{ page.parent.parent.uri }}~*~m={{ page.slug }}#{{ page.slug }}">📝</a>
Did the current visitor toggle the flag. Does not read login, only uses a hashed IP address as identifier md5(kirby->visitor->ip())
.
didLike();
didStrike();
didBell();
didEdit();
didPhoto();
returns 1 or 0
likeCount();
strikeCount();
editCount();
bellCount();
photoCount();
PHP Template
<?= page->strikeCount() ? "⛔" . page.strikeCount() ?>
or as Twig Template
{{ page.bellCount() ? "🔔" ~ page.bellCount() }}
YAML Blueprint
fields:
likes:
label: Likes
type: likes
strikes:
label: Strikes
type: strikes
edits:
label: Edits
type: edits
bells:
label: Bells
type: bells
photos:
label: Photos
type: photos
Individual flags cannot be removed but each count can be reset to zero.
Does Not function on 'Home' pages.
The route pattern for this was included in 'kirby-likes' but it was unnecessary for this context.
Significant diversion in purpose from medienbaecker/kirby-likes and not to be merged back, ever.
Customized specifically for an internal CMS. No pull requests will be approved but by all means fork and copy.
All the credit and ❤️ to Thomas Günther @ https://github.com/medienbaecker.