Not sure what you mean by more "code space" -- though I can assume its what you have currently on your sandbox (?).I just try to do the same thing as, for example, in https://hoi4.paradoxwikis.com/Land_warfare
There is a separate template (called "WarfareNavbox"), which can be called in a single line {{Template:WarfareNavbox}}
I can add a navbox for mechanics on page using standard "Navbox" template, but it takes more code space
Is this the way to do it, or do I need to create a separate template source?
In essence, templates are used to place the same content on multiple pages via transclusion.
Since navboxes fall into that category then you'll need to create a template with the content from your sandbox and then call the template from whatever page you want.
Hope it helps. If you got more questions feel free to PM me or one of the other editors.