kanweb / c5-helpers
ConcreteCMS 辅助工具套件
v2.1
2021-11-23 10:37 UTC
Requires
- php: >=7.4
- xanweb/c5-common: ^1.2
This package is auto-updated.
Last update: 2024-09-23 16:42:01 UTC
README
ConcreteCMS 有用辅助工具集合
in_array_all验证所有针都在草堆数组中。in_array_any验证至少有一个针在草堆数组中。strip_spaces从给定字符串中删除所有空格。current_locale获取当前页面区域设置。current_language获取当前页面语言。active_locale是 \Localization::activeLocale() 的别名。active_language是 \Localization::activeLanguage() 的别名。theme_path获取站点主题路径c5_date_format是 \Concrete\Core\Localization\Service\Date::formatDate() 的别名。c5_date_format_custom是 \Concrete\Core\Localization\Service\Date::formatCustom() 的别名。Xanweb\Helper\Page::getBlock和Xanweb\Helper\Page::getBlocks用于从页面获取块
安装
将库包含到 composer.json 中
composer require xanweb/c5-helpers
Xanweb\Helper\Page 的用法
use Xanweb\Helper\Page as PageHelper; $ph = new PageHelper( $page, // Page Object ['Header', 'Footer'], // Optional argument to exclude some areas from fetching ['Main'] // Optional argument to include some areas in fetching ); // Get the first valid instance of required block $contentBlockController = $ph->getBlock( 'content', // Block Type Handle function (BlockController $bController) { // Optional callable to test for valid block return !empty($bController->getContent()); } ); // Get the first valid instances of required blocks $blocksControllers = $ph->getBlocks( ['image', 'content'], // Block Types Handle function (BlockController $bController) { // Optional callable to test for valid block if ($bController instanceof \Concrete\Block\Image\Controller) { return is_object($this->getFileObject()); } if ($bController instanceof \Concrete\Block\Content\Controller) { return !empty($bController->getContent()); } return false; } ); /** * - $blocksControllers array is indexed by btHandle: ['image' => $bController, 'content' => $bController] * - If no block is found $blocksControllers will be an empty array */