Comments (4)
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.
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.
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.
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)
- Error: Fractal themes must inherit from the base Theme class. HOT 4
- Make subnavigation for variants configurable
- URL inconsitency dev-server/build HOT 4
- Split react adapter helper components into another package
- Feature: @partial-block for nunjucks engine HOT 5
- Build will not run properly if there is a hidden directory in the path HOT 3
- Twig adapter returns "unable to parse" error depending on include-statements location in DOM HOT 1
- Add option to exclude timestamp from build component files HOT 2
- DeprecationWarning: Invalid 'main' field in package.json HOT 3
- Inefficient Regular Expression Complexity in marked HOT 1
- Sync not working on documentation section HOT 5
- PSA: status of project & looking for maintainers! HOT 6
- Vulnerabilities in Frctl HOT 3
- Search no longer filters results HOT 4
- Require is not defined - new Fractal installation HOT 2
- Is Nodejs v18.12.1 LTS supported? Is this module still maintained? html is escaped HOT 6
- Twig.js new release (1.16.0) dependency breaks the fractal adapter with this error: TwigException: Cannot extend an inline template HOT 1
- Add Mozilla Protocol design system to home page/fractal in the wild HOT 2
- Bug in nav-collapse margin-inline sizing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fractal.