Add function to get a group of modules based on a json path
Hello,
I added this function to get modules from any type of manifest structure, as it is not always a flat one.
Initially I did this to simplify the use of Create React App with Craft CMS, but it’s not limited to this particular case: with this modification we can get any file from the manifest, whatever its structure (as long it’s a valid json)
For example, considering this manifest:
{
"style.css": "css/style.sfkjsf734ashf.css",
"app.js": "js/app.gldlkg983ajhs8s.js"
"editor": [
"css/editor/index.css",
"js/editor/index.js",
"plugins": [
"js/editor/plugins/importbmp.js",
"js/editor/plugins/export.js",
]
],
"store": [
"preview": "js/store/preview.js",
"standalone": [
"js/store/index.js",
"js/store/chat.js",
]
]
}
It is now possible to get the content of the editor group like this:
{{ craft.twigpack.getModuleTagsByPath("$.editor.plugins") }}
or we can simply get a single file:
{{ craft.twigpack.getModuleTagsByPath("$.store.preview") }}
Because underhood it use the JsonPath specification, so any path type is supported, imho it adds a lot of flexibility to this great plugin.
Let me know what you think about it.
Ah I'm sorry I missed this PR somehow @fraqe -- on the surface, I like the idea. My concern is testing, but I'll have a look!
No problem, for the moment I use my forked version and it meets my needs. If this PR can be useful to other people and needs a little more work to be merged, let me know.
I'm going to want to revisit this as a part of supporting Vite and the different manifest.json they support.