I'm interested in building a highly modular Craft site in which my folder structure might look something like this:
- craft/
- modules/
- hero-banner/
index.html
scripts.js
styles.css
- carousel/
index.html
scripts.js
styles.css
- templates/
404.html
index.html
_layout.html
index.php
robots.txt
.htaccess
An example of what hero-banner/index.html
would look like:
<div class="hero-banner__contain">
<div class="hero-banner__content">
<h2 class="hero-banner__title">{{title}}</h2>
<p class="hero-banner__subtitle">{{subtitle}}</p>
</div>
<img src="{{image}}" alt="{{title}}">
</div>
An example of how you'd use this in a Craft template like templates/index.html
:
{{
craft.componentUI.run('hero-banner/index', {
title: 'Welcome to my site!',
subtitle: 'This is an intro paragraph that has a bit more detail about this site.',
image: 'http://dummyimage.com/800x350/000000/555555'
})
}}
A couple reasons I'd like to do something like this:
- To create a parity between a style guide and the live site. This way a change to
hero-banner/index.html
would be reflected in the style guide and the live site. I understand a partial can do the same thing, but I'd prefer something like this because... - We can encapsulate a module's HTML, CSS and JavaScript in one place. Doing this will allow us to utilize Git or npm to manage these modules individually if we'd like to use them on other sites. It also makes locating a module's assets much easier since they're centrally located rather than being in 3 different folders.
I've found a way to reference template files outside the standard templates/
directory to make this work. So I know this sort of setup can work.
However, my question is what problems could arise from this type of setup? Do I need to be concerned about performance/security/something else entirely?
Edit: Just for further clarification, I'm not looking to serve my CSS and JS through Craft. I want to keep my CSS and JS as-is, but wondered if I could call the modules from those directories (outside of the normal Craft templates).