Robin S Posted February 28, 2017 Posted February 28, 2017 I just noticed that HTML comments in a template file are not rendered in the front-end source. Which is totally fine with me, very useful in fact, but I'm wondering what part of PW is responsible and when this started happening. I know that ProCache strips HTML comments, but I don't think that is the cause in this case because I currently have it disabled and comments are still not rendered. Was it introduced by the file compiler starting in PW3? Or maybe part of the new Markup Regions feature (which I have enabled) ? Or has this always been the case and I just never noticed? To be clear: HTML comments in _main.php are rendered, just not those in a template file. Wrong forum section sorry. Meant to post this in General Support.
Macrura Posted February 28, 2017 Posted February 28, 2017 It must be pro cache; i have a site with pro cache enabled and i don't have it set to strip comments, and my comments still appear; have you tried turning off the html minification features of PC? i believe it still processes, even when the caching is off. 1
Robin S Posted February 28, 2017 Author Posted February 28, 2017 1 hour ago, Macrura said: It must be pro cache I have ProCache disabled from the main "ProCache enabled?" checkbox, which turns all ProCache features off including minification I believe. I uninstalled ProCache to be sure and did a bit more testing. Seems to be an unannounced side-effect of the Markup Regions feature. When this is enabled in config.php all HTML comments both inside and outside a markup region in a template file are stripped out of the compiled output (edit: clarified below). I don't mind that as it's useful to be able to put notes and separators into the markup that are better kept out of the front-end source. I was just a bit surprised as this wasn't mentioned in the blog posts.
Macrura Posted February 28, 2017 Posted February 28, 2017 right that is strange - is markup regions something that you can enable/disable? I know for sure i need comments in my HTML to stay put for the most part.
Robin S Posted February 28, 2017 Author Posted February 28, 2017 23 minutes ago, Macrura said: is markup regions something that you can enable/disable? Yes, the first blog post on the feature says that for now it must be explicitly enabled in $config: $config->useMarkupRegions = true; You have to be deliberately using the feature too in order to be affected by the stripped comments. So contrary to what I said above it isn't so much that useMarkupRegions is enabled, it's when there are comments in the HTML that occur before the doctype or <html> tag. Quote How does it work technically? It's actually really simple. When ProcessWire renders a page, it now asks the question: does any markup appear before the doctype or <html> element? And if it does, does any of it reference "id" attributes or have "pw-" prefix classes? If so, it processes them as markup regions, letting you do all that's mentioned in this post. ---- _main.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><?= $page->title ?></title> </head> <body> <?= $my_var ?> <!-- this comment will be rendered --> <div id="main"> <p>Default main content.</p> </div> </body> </html> home.php <?php $my_var = " <!-- this comment will be rendered --> <p>hello</p> "; ?> <!-- this comment will not be rendered --> <div id="main"> <!-- and this comment will also not be rendered --> <p>Main content from home template.</p> </div> 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now