0

I have a project that uses a lot of template strings, that I want to convert to separate HTML files.

I know Visual Studio Code can move JavaScript to a new file. Can it do the same with HTML string content?

The closest I can do is extract the JavaScript string to a new file, and then rename it and change the extension.

I've not found an issue in the Visual Studio Code GitHub account or any other questions about this.

So I want to go from this:

const MY_TEMPLATE = `<div>{{unicorn.fart()}}</div>`
function useTemplate(imports){
    return {
        template: MY_TEMPLATE,
        scope: {
            unicorn: imports.getUnicorn('charlie')
            onFart: imports.refuelCar(imports.ELECTRIC_CAR)
        }
    }
}

Highlight the string in the MY_TEMPLATE select a right click menu, and then get this:

import template from './MY_TEMPLATE.html'
function useTemplate(imports){
    return {
        template,
        scope: {
            unicorn: imports.getUnicorn('charlie')
            onFart: imports.refuelCar(imports.ELECTRIC_CAR)
        }
    }
}

Is there a setting to change, a version to install/wait for or a plugin?

1 Answer 1

1

This does not exist as of Visual Studio Code 1.29. Since this is a very specific feature request, and it would best be implemented by an extension and not as part of core Visual Studio Code.

See this guide for information on how to get started writing a Visual Studio Code extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.