markjgsmith

Blog

Text template rendering should be standard in all operating systems

2023-08-21 08:11:00 +0700 by Mark Smith

It should be possible no matter where you are located or what you are doing to render out a template and get back the resulting string of text in a way that you can use it to accomplish the task you are doing.

Seems like an easy ask, but it's actually quite tricky because the UI is different depending on where you are and what you are doing. What that means is that it's not obvious how you get or provide the required inputs to the template rendering, but also how you use the resulting string.

Are you on the command line in a shell? Or on the Desktop? Or maybe you are in an app?

Where are the inputs you need to insert into the template? How are you going to get those? Manually type them? Auto generate them by running a script?

What are you going to do with the rendered string? Copy and paste it? Stick it in a file? Perhaps insert it into a form?

Once you stop to think about it for a few minutes, it's not at all obvious how to implement a system wide feature like template rendering.

The most obvious way might be to make it an enhancement to the standard copy / paste feature of the operating system. Have a way to run a script to fetch data, pass it into a template you select, and get back the rendered output on the clipboard ready to do with it as you please.

That would be really useful to me right now. I already have a title for this post. It's right there in the frontmatter. What I want to be able to do is select the title using the standard operating system copy feature, then run it through a template that would transform it as follows:

Text template rendering should be standard in all operating systems

would get transformed to:

text-template-rendering-should-be-standard-in-all-operating-systems

That would give me the text slug which I could use in the filename of this blog post's markdown file.

2023-08-21-081100-text-template-rendering-should-be-standard-in-all-operating-systems.md

You would probably need to have a library of utility functions you could use in your templates. In this case we would need some sort of slugify utility function as well as datetime manipulation functions.

I could continue using whatever editor I was using as normal, using it's 'Save As' feature, but no need to mess about getting the filename correct. In a couple of clicks it would be correct every time. It's small features like this that have the potential to remove huge bariers.

For enquiries about my consulting, development, training and writing services, aswell as sponsorship opportunities contact me directly via email. More details about me here.