Use Fractal Styleguide in your PHP project.
- 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();
});
- 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()