2

I'm a emacs beginner, hope this not a stupid question.

Here is the issue: when I open a html file that contains php block, every html thing got correct syntax highlight, but the php block. The web-mode version is 12.2.10, and emacs is 24.5.1. And when I open a php file contains html codes, everything works fine.

The following is my web-mode configuration:

(require 'web-mode)

(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.html$" . web-mode))

(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))

(add-to-list 'auto-mode-alist '("\\.php$" . web-mode))

(setq web-mode-engines-alist
      '(("php"    . "\\.phtml\\'")
        ("blade"  . "\\.blade\\.")))

enter image description here

What else should I do to make this right?

Thanks in advance.

2 Answers 2

5

You should add (setq web-mode-engines-alist '(("php" . "\\.html\\'"))) in your .emacs. Indeed, web-mode.el can not guess the template engine with such a generic extension. You can find more informations about web-mode-engines-alist on http://web-mode.org

0
2

Scenario 1: You are editing your own files.

In this case, and if possible, it's better to identify the kind of HTML file you are editing by a unique extension: .djhtml for django files, etc.

Scenario 2: You are editing your own files, but for some reason you are obliged to use the generic .html extension.

Add a comment to your .html file:

<?php /* -*- engine:php -*- */ ?>

Scenario 3: You are editing (or just browsing) someone else's files.

So now you are unable to change the file extension or to introduce a comment line in each file.

In that case add

(setq web-mode-engines-alist '(("php" . "\\.html\\'")))

to your .emacs, but beware that you are now in "php-only mode", in the sense that if you view/edit a .html file that contains, say, django markups, it will still be interpreted as php.

Your Answer

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

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