hananils/kirby-type-methods 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hananils/kirby-type-methods

Composer 安装命令:

composer require hananils/kirby-type-methods

包简介

Type Methods is a plugin for Kirby helping to identify the type of an object, either page, user or file, in order to simplify logic in snippets that – for instance – handle content from both $page and $user objects.

README 文档

README

Kirby Type Methods

Type Methods is a plugin for Kirby helping to identify the type of an object, either page, user or file, in order to simplify logic in snippets that – for instance – handle content from both $page and $user objects.

Note

Please check out the online documentation at kirby.hananils.de/plugins/type-methods for further information.

Examples

Think of site where you want to list members. Member information is either stored with the Kirby users (for admins) or on pages (for regular members). Given you have an array of all members, containing either user or page objects, type methods will help you to identify the source:

<?php foreach ($members as $member): ?>
  <?php if ($member->isUser()): ?>
    <?= $member->username() ?> (<?= $member->role() ?>)
  <?php else: ?>
    <?= $member->title() ?>
  <?php endif; ?>
<?php endforeach; ?>

There is also a shortcut to check the given template or role respectively:

<?php if ($member->isType('parents')): ?>
  <!-- do stuff specific to all pages with the `intendedTemplate` of `parents` -->
<?php elseif ($member->isType('admin')): ?>
  <!-- do stuff specific to all users with the `role` of `admin` -->
<?php endif; ?>

Using isType() is both shorter than checking intendedTemplate or role and also doesn't require you to check first which object you are dealing with (page or user).

Installation

Download

Download and copy this repository to /site/plugins/type-methods.

Git submodule

git submodule add https://github.com/hananils/kirby-type-methods.git site/plugins/type-methods

Composer

composer require hananils/kirby-type-methods

Methods

These methods work on page, user or file objects:

isPage()

Checks if the given object is a page.

$object->isPage();

Returns either true or false.

isUser()

Checks if the given object is a user.

$object->isUser();

Returns either true or false.

isFile()

Checks if the given object is a file.

$object->isFile();

Returns either true or false.

isType('template')

Checks if the object has the given template.

$page->isType('article');

Returns either true or false.

License

This plugin is provided freely under the MIT license by hana+nils · Büro für Gestaltung. We create visual designs for digital and analog media.

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固