Giter VIP home page Giter VIP logo

Comments (4)

jfroehlich avatar jfroehlich commented on June 8, 2024 1

Ok, I put together a little sample project: https://github.com/jfroehlich/nunjucks-fractal-example
It works fine in that little lab project, but I didn't try it in production yet.

from fractal.

mihkeleidast avatar mihkeleidast commented on June 8, 2024

Yeah, I think this is necessary, though we should agree on what specific circumstances we should document. For example, integrating a Twig component library into a WordPress (or any PHP) project can differ a lot compared to some Node-based CMS-es.

I think in the past the easiest way to do a semi-direct integration is to export a handle/filePath map from Fractal and then integrate that into the CMS template loading stack.

from fractal.

jfroehlich avatar jfroehlich commented on June 8, 2024

Oh, this is a great idea! A map like {<handle>: {<filePath>, <context>}} would be great starting point to build the render tag for various template systems, I guess. The implementation of the tag is certainly very similar for nunjucks, twig, handlebars, django, jinja2, liquid, ... and an official reference implementation for nunjucks or handlebars could bootstrap the implementation of these plugins very quickly.

A way to export this map is already (kind of) documented. I slapped a little proof of concept function together which runs fine in my fractal skeleton, but does not yet write files:

fractal.cli.command('list-components', function (args, done) {
    const app = this.fractal;
    const sourcemap = {};
    for (let item of app.components.flatten()) {
        sourcemap[item.handle] = {path: item.path, ctx: item.context}
    }
    this.log(JSON.stringify(sourcemap));
    done();
}, {description: "List components"});

Is that the right way to do it? Is there an API endpoint to write the file?

The file could be updated on the fly with the updated event. Correct?

Do you by chance already have a simple nunjucks or handlebars tag that processes this file? If not I'd try a bit on the weekend.

from fractal.

mihkeleidast avatar mihkeleidast commented on June 8, 2024

Yes, exactly! Fractal does not offer an API to write files, but you should be able to use the Node-native fs API for that.

I don't have an example on how to use the map in another Nunjucks/Handlebars environment, I've only ever made it work with Twig PHP (for WordPress through Timber) myself.

from fractal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.