dxw/govpress-blocks

WordPress 重复使用的自定义模块

dev-main 2022-08-08 12:25 UTC

README

一个用于在 GovPress 项目中使用的可重复使用模块库。

如何使用

  1. 在您的主题中安装包
    composer require dxw/govpress-blocks
    
  2. 使用工厂创建您想要使用的模块,并传递任何配置,例如:创建一个带有默认配置的卡片模块
    \Dxw\GovPressBlocks\Factory::create('card');
    
    创建一个渲染自定义模板的卡片模块
    \Dxw\GovPressBlocks\Factory::create('card', [
      'template' => '\the\full\path\to\your\custom\template.php`
    ]);
    
    对于 dxw 项目,建议将此代码添加到主题的 app/di.php 中,如果主题使用 Iguana
  3. 如果您想使用模块的默认样式,请将其导入到主 SASS 文件中,如下所示(路径中的最终名称是模块类型)
    @import 'vendor/dxw/govpress-blocks/assets/scss/blocks/card'
    

以下文档化了可用的模块。

模块

卡片

\Dxw\GovPressBLocks\Factory::create('card', array $config)

配置选项

[
    'template' => string $theFullPathToYourCustomCardTemplate
]

SCSS

@import 'vendor/dxw/govpress-blocks/assets/scss/blocks/card'