I have a file style.php
that contains css primarily and php in some areas. Syntax highlighting is completely broken in this scenario.
<?php
header("Content-type: text/css");
?>
:root{
--some-css-variable: <?php echo get_theme_mod("some_variable")?>
}
body{
background: pink;
.
.
.
}
I've tried a bunch of extensions and ancient forum post suggestions, but I cannot get vscode to recognise the php for what it is and the CSS for what it is.
I'm perfectly fine having to manually choose a language mode of (for instance) php+css
, comment annotate that the outside is css, or whatever else - since it's not obvious that the non-php part is css. But I've found zero solutions, to what seems like a fairly common scenario.
Does anyone know how to fix this?
Add style tags around your style definitions and remove them on output. You can do it like following:
<?php if (false) { ?>
<style>
<?php } ?>
body {
background: pink;
}
<?php if (false) { ?>
</style>
<?php } ?>
It's not that nice but it works on my own VSCode.