You’re reading diehealthy.org

Document Templates.

Even this very post started as a copy of a template!

I only have a few document templates that I use with GNOME (I think it works similarly for KDE or others), but I find them pretty handy, so I figured I’d mention what I use.

My most-used template is for these blog posts. It used to be a Markdown template, but as I moved away from using Markdown when I stopped using a block theme, I now use an HTML template.

The beauty of the template system is it’s simply a copy-paste of the file you place in ~/Templates (or in the location specified by XDG_TEMPLATES_DIR), but it works off a handy menu in GNOME Files (Nautilus) where you select New Document and then the type of template to use. The new file will have the same filename as the template, along with all its content.

I use two different HTML templates. One is for any old HTML I might want to write as a one-off document, experiment, whatever. The other one is specific for blog posts.

For posts, I add a style element to pull in my local copy of my blog’s stylesheet, in case I want to open the file directly and get an idea how the post might look. I also have a comment above the post body that includes metadata I can keep track of:

  1. Title
  2. Tags
  3. Excerpt
  4. Image filename and alternate text

That comment also includes a cheat-sheet of my commonly-used HTML snippets I have set in Geany, where I do most text editing and writing. These snippets let me type something like link, hit Tab, and have it spit out the basic HTML for a link (including target and rel), so I can simply fill in the URL and the link text.

Anything post-specific, I can always look-up or build at the time, so the template only contains things that are fairly common in posts. It’s a basic system, but it saves me a decent amount of time when I want to write a new post.

The last template I use often is one for Python. It’s fairly sparse, but it gives me a Shebang that will tell a shell to run it correctly, and it gives me the basic run-alone clause at the bottom:

if __name__ == '__main__':
    print('Hello, world!')
Telling Python to only print “Hello, world!” when the file is run directly.

If I’m creating a new Python script from scratch, that’s what I’ll want, so I won’t have to type it out. I can quickly write a few functions, and I’m ready to go.

In the case of Python, I could probably add some extra things, like commented lines listing common imports, or maybe even a few helper functions, but I usually go look those things up to remind myself how to use them if I need them, so it might not save much time. I tend to write fairly simple scripts, only moving to object-oriented code if a script is becoming complex—to avoid it becoming complicated, so having stub classes aren’t necessary.


I’d be curious to see what people who push it farther have done with it. A web search didn’t turn up any obvious big write-ups or repositories. Several git repositories hits (unlinked) had every filetype under the Sun, but most of their templates were stub files rather than anything custom or innovative.


browser add-on

Stylus

Write or import your own CSS styles into regular webpages.

Please Deposit Two Cents:

This site uses Akismet to reduce spam. Learn how your comment data is processed.