fcog/fractal-handlebars-php

PHP 和 Handlebars 的 Fractal 风格指南模板加载器

1.0.4 2020-08-04 17:37 UTC

This package is not auto-updated.

Last update: 2024-09-26 08:47:15 UTC


README

在您的 PHP 项目中使用 Fractal Styleguide

  1. 使用 Fractal 的 API 创建组件的映射文件。
const path = require('path');
const fs = require('fs');

function exportPaths() {
    const map = {};
    for (let item of fractal.components.flatten()) {
        map[`@${item.handle}`] = path.relative(process.cwd(), item.viewPath);
    }
    fs.writeFileSync('components-map.json', JSON.stringify(map, null, 2), 'utf8');
}

fractal.components.on('updated', function(){
    exportPaths();
});

fractal.cli.command('pathmap', function(opts, done){
    exportPaths();
    done();
});
  1. 加载渲染器库。
$view_engine = new Renderer(
    get_template_directory() . '/component-library/',
    get_template_directory_uri() . '/component-library/assets'
);

// In some template file
$view_engine->render('@fractal-component-handle', ['data_prop' => 'value']);

注意:components-map.json 应该位于传递给 Renderer() 的第一个参数所在的目录中

致谢

rodger

allmarkedup

更多信息

frctl/fractal#190