Sublime Forum

HTML/Javascript SYntax highlighting bugs with Smarty tags

#1

I’ve started getting syntax highlighting errors when using Smarty that are driving me up the walls. I didn’t use to get them, but even fully reinstalling Smarty to default state isn’t getting rid of them.

Basically, often when I’ll type a slash inside Smarty text within a jaavascript script tag, everything that follows is just messed up. Short example:

I really have no idea why this is happening. Can I just completely ignore any / following a curly bracket directly or something? It’s really getting under my skin, and even installing some SMarty specific package for Sublime Text that I found did not solve the issue.

0 Likes

#2

Still suffering from this. The same files on different computers don’t have the problem, but no matter how cleanly I reinstall Sublime this keeps occuring for me.

0 Likes

#3

The core HTML syntax does not provide support for embedded scripts other than HTML and JavaScript. It looks like JavaScript highlighting is being applied to your Smarty code. Most likely, this is because it is inside a <script> tag that does not specify a non-JavaScript type attribute.

The only solution is to use a third-party syntax that explicitly supports Smarty.

0 Likes

#4

Here you are. You’re welcome.

0 Likes

#5

Thanks for the feedback.

Sadly, installing the Smarty package and setting the file to Smarty didn’t solve it, but I suppose little else can be done.

0 Likes

#6

Here is how I improved my smarty syntax highlighting in Sublime 3 for files with JS.

First, set your smarty JS files to open with Javascript syntax. I name my files with smarty and JS with a special extension of filename.tpl.js

  1. Install Package​Resource​Viewer
  2. Edit Package Resource
  3. Choose Javascript
  4. Edit the Javascript.sublime-syntax
  5. Make the following edits:

Make the following edits.

Line 72 change

  • match: /*
    to
  • match: /|{

Line 77 change
from

  • match: */
    to
  • match: /|}

Line 874
from

  • match: ‘/’
    to
  • match: ‘(?<!{)/’

It’s not perfect, but it really helps.

0 Likes