Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Richard Nash
Richard Nash
24,862 Points

Do HTML partials exist?

As I'm learning the modular Sass course and applying these ideas to my own work I've come to love using partials and being able to split up my css into small files, called partials, and compile them together for my sites output.

I also remember watching the php course and seeing a similar idea happen but breaking html up into small chunks and dynamically adding them to a webpage without having to re-write, or copy and paste code.

I'm interested in knowing if their are any html preprocessors that use a similar partial structure for writing html and breaking the html up into modular files, or partials, that can then be compiled and outputted as standard html.

I've found things like haml, jade and others but i do not understand them very well. So if anybody has any insight into this I would appreciate it very much :-)

6 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Richard,

In the past year or two a new HTML5 specification called Web Components has arrived and is now fully supported as of Chrome 36, Opera 23, Android browsers as of 4.4 and Chrome for Android as of 37.

Now this is good if you develop on the bleeding edge but not so good in practise as it simply doesn't help in general but the guys over at Google who pioneered this have written a framework called Polymer which is based completely around Web Components, Polymer is a modular framework so you only use what you need to from it and it does the grunt of the work.

For older browsers Polymer has graceful fallbacks using ajax and clever DOM manipulation so performance isn't an issue in that regard.

James Barnett
James Barnett
39,199 Points

Various HTML preprocessors appear to have partial support

I found this list as item 8 on google for haml partial

http://fireapp.kkbox.com/doc/template_layout_partial.html

Colton Fitzgerald
Colton Fitzgerald
15,815 Points

The creator of Sass also made a language called "Haml" but I'm not sure if it does anything like that. Maybe it's something to look into! Otherwise, the way I do it is with PHP includes.

Richard Nash
Richard Nash
24,862 Points

thanks for the info Chris Upjohn :-) This looks interesting, indeed :-)

Daniel Elebash
Daniel Elebash
91 Points

This is not a pre-processor for html, but if want to componentize your html you can use angular's router it allows for partial views. Also there is angulars ng:include.

You can use jquery's ajax to dynamically load html pages as partials, I believe this is what is happening under the hood in angular's partial views.

Richard Nash
Richard Nash
24,862 Points

hmmmm... it seems like modular web design is just around the corner. Gonna dive into all these links and figure it out.

Thanks everybody! XD

R