0

I'm trying to use KnockoutJS in my web framework, which uses plain Smarty.

Some parts of KnockoutJS's syntax use comments in the form of <!-- ko foreach: array -->.

Smarty strips all HTML comments (except IE conditionals), including these ones.

I can remove the responsible preg_replace line in Smarty, but I'd rather have solution where I don't have to change third party code.

Is there any way to skip the comment stripping in Smarty?

Martijn
  • 3,696
  • 2
  • 38
  • 64

1 Answers1

0

Actually Smarty displays all HTML comments such as <!-- comment --> in the final output of the template. Only the Smarty-specific comments {* this is a comment *} are hidden in the final output. Your framework may be hiding the HTML comments in the back-end, perhaps for HTML compression.

Refer to Smarty Comment Syntax

Jay Na
  • 807
  • 2
  • 9
  • 20
  • You may be using an old version. The current version (3.1.13, and several versions back) have a plugin named `outputfilter.trimwhitespace.php`, which contains a line `$source = preg_replace( '##ms', '', $source );`, which does the comment stripping. As far as I know, the filter cannot be disabled or removed without altering code or removing the file. – Martijn Apr 20 '13 at 06:14
  • I apologize. I had little idea about the new plugin. – Jay Na Apr 20 '13 at 19:04
  • Martijn is incorrect, outputfilter.trimwhitespace.php is not enabled OOTB. It must be explicitly enabled in the PHP code. You could simply not enable it. – mohrt Aug 27 '15 at 16:33