Partial Hungarian Notation

Published

I’ve been working with {{mustache}}-y1 templates recently. Both for this blog as well as a personal project that generates static sites/blogs from Markdown in effectively a bash script. That’s for another time, though.

Partials in Mustache

Mustache has the concept of partials which can be thought of like includes/imports that get rendered at runtime (compared to compile time) and inherit the calling context.

The contrived example (from their docs) is something like

// base.mustache:
<h2>Names</h2>
{{#names}}
  {{> user}}
{{/names}}

// user.mustache:
<strong>{{name}}</strong>

which would end up as

<h2>Names</h2>
{{#names}}
  <strong>{{name}}</strong>
{{/names}}

Enter Sass/SCSS Partials

I’m also familiar and a proponent of Sass/SCSS which features partials too—although here they function closer to a traditional import. The kicker is that files must be prefixed with an underscore e.g., variables.scss_variables.scss to avoid being compiled into a CSS file.

Implying Intent: Hungarian Notation

I’ve gotten in the habit of prefixing my Mustache partials with an underscore e.g., footer.html_footer.html. This doesn’t functionally do anything differently, it just gives me context to the file being a partial and not something standalone. This implied intent is referred to as Hungarian Notation.

So now, consider the scenario where there’s a partial that doesn’t fall into that same category: a partial within a partial or maybe one that deals with data not native to the template but still gets rendered. At any rate, it doesn’t fit the paradigm: it’s a partial partial. For this, I propose the *drumroll* double underscore prefixed __partial.html.

I’m not sure if it will stick, but I’ve been trying it out with the projects mentioned in the beginning and so far 🤞 it is. To allow myself once final iteration: it’s about the implied intent since I spend many magnitudes more time reading code versus writing it.


  1. N.B. I needed to set a custom delimiter to even write out the double-stache syntax. 🤓↩︎


I love hearing from readers so please feel free to reach out.

Reply via emailSubscribe via RSS or email

Last modified  #meta   #dev   #templating   #naming 

🔗 Backlinks

← Newer post  •  Older post →