Sublime Forum

Sublime Text 2 as '@includes' substitution

#1

So in my current situation, I’m building out a library of information on my company’s product. It’s an internal library. The boss has told me that I have to code it locally as HTML/CSS and post it to Git. Others wanting to use it will then pull the repository and open it locally.

So–no PHP@includes, no Server Side Includes.

Is there a way to ‘@import’ or ‘@include’ files, just like I would do with PHP? e.g. I build out a ‘navigation.html’ file, and maintain my navigation in that one file. In all of my other files, I’d just do navigation.html, and get my menu generated in that fashion?

Thanks!

0 Likes

#2

Client-side includes is the terminology, but it’s not as straight-forward as just including a file. (The link discusses the process, and advises of some pitfalls.)

Essentially, you can attach a javascript file, which includes a function, which uses document.write to write to the file at the current location.
Easier would be to use an **iframe **to include content at a specific point in your document.
A third alternative occurs to me - which is to wait until the document has loaded and use JavaScript to manipulate, and append to, the DOM-body - but there is probably no advantage to this approach compared to the first mentioned method.

If you decide to pursue a copy/paste approach you could consider adding specific comments at certain points in the files and use ST’s Find/Replace in Files feature (or some other file utility) to replace (or append after) the comments in one fell swoop. I think you would need to plan this carefully, and I would consider something like this:

**

**

so that you could insert the text between these comments and repeat the process at a later-stage if you needed to. Andy.

0 Likes

#3

The javascript client side includes was a good solution, thank you!

0 Likes