fcog/fractal-handlebars-php

Fractal styleguide template loader for PHP and Handlebars

1.0.4 2020-08-04 17:37 UTC

This package is not auto-updated.

Last update: 2024-05-09 07:08:53 UTC


README

Use Fractal Styleguide in your PHP project.

  1. Create the component's mapping file using Fractal's 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. Load the renderer library.
$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']);

Note: components-map.json should be in the same directory of the first argument passed to Renderer()

Credits

rodger

allmarkedup

More info

frctl/fractal#190