2

I am a WebStorm user.. never touch Visual Studio

All Display Templates in HTML are comments, and displayed accordingly in my IDE

Does Visual Studio (Code) do syntax highlighting and intellisense on these files?

1
  • No, but I saw a blog post somewhere about how to flip it around so the code is outside of the comments and you get highlighting/intellisense. I will see if I can find it again. Commented Feb 8, 2016 at 19:19

2 Answers 2

1

VisualStudio does not do it, but there is a workaround.

The trick is to put all your JavaScript code in a script block in the regular HTML section of the template. You need to create a function that will return an object with all the data you need for your template.

Then you register your function the same way SharePoint registers all the generated display template functions.

Then in the comment section that eventually gets turned into code, you call your function and use the results.

Here's the blog post that describes how to do it in detail:

http://www.eliostruyf.com/get-javascript-intellisense-syntax-highlighting-html-display-templates/

1
  • That is what I do now, not with a script block but an external library Commented Feb 8, 2016 at 19:41
0

There are a few different options, depending on what platform you're using on your local machine.

However, neither of these options will do syntax highlighting within the comments. I find that frustrating too, since so much SharePoint code is written that way, but I've yet to find a way to work around that.

Windows

Your best bet on Windows is to use Visual Studio Community Edition. You can download it from the home page on VisulStudio.com or directly from this link. You can use Code on Windows, but VSCE is probably a better choice for most people. Intellisense is much more robust in VSCE, at least in terms of referencing the standard CSS classes and such in SharePoint.

You can also do some editing in SharePoint Designer, but it's much more limited and (in my opinion) more difficult to work with for tasks like this than either Code or VSCE

Mac/Linux

On other platforms, Visual Studio Code will basically do the same syntax highlighting as Visual Studio Community, but it doesn't seem to have as much built-in knowledge about SharePoint. It's the only "official" tool for SharePoint design on OS X or Linux at this time.

There is one Code extension for SharePoint development listed on the Visual Studio Marketplace, but I've not used it personally.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.