Umbraco v6.1.6集成AMP样板代码时出现解析错误求助
Hey there, let's figure out this AMP parsing error you're running into with your Umbraco v6.1.6 MasterPage.cshtml!
First, let's recall AMP's strict rules around styles—this is almost certainly where your issue lies, even after removing whitespace. Here's what to check step by step:
1. AMP doesn't allow inline style attributes (with very few exceptions)
AMP only permits one single <style amp-custom> tag in the <head> for all your custom CSS. Any inline style="..." on elements (like <div style="padding: 10px;">) will trigger a parsing error.
Even if you thought you removed whitespace, if your template (or Umbraco's built-in controls) are rendering inline styles on elements, that's a no-go. You'll need to:
- Replace all inline styles with CSS classes
- Move those class definitions into the
<style amp-custom>block in your<head>
2. Double-check your AMP boilerplate code
Make sure your MasterPage starts with the exact required AMP boilerplate—missing or malformed parts here can also cause style-related parsing errors. Your template should open with:
<!doctype html> <html amp lang="en"> <head> <meta charset="utf-8"> <script async src="https://cdn.ampproject.org/v0.js"></script> <title>@ViewBag.MetaPageTitle</title> <!-- Don't forget the canonical link to your non-AMP page --> <link rel="canonical" href="@Request.Url.AbsoluteUri"> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <!-- Your custom styles go HERE --> <style amp-custom> /* Example: .my-padding-div { padding: 10px; } */ </style> <!-- Required AMP boilerplate styles --> <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style> <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> </head> <body> <!-- Your page content here --> </body> </html>
3. Watch out for Umbraco-specific quirks
Umbraco v6.1.6 is a pretty old version, so some built-in macros or controls might automatically render inline styles (like for rich text editors, or default layout elements). You'll need to:
- Check any RTE output in your templates—make sure it's stripped of inline styles, or configure the RTE to use classes instead
- Audit any Umbraco-generated HTML to ensure no unexpected
styleattributes are being added
4. Use the AMP validator to pinpoint the exact error
To get precise details on which style rule is causing the issue, enable AMP validation in your browser's dev tools:
- Open Chrome DevTools (F12)
- Go to the Console tab
- Type
amp.toggleValidation()and hit enter - Refresh your page—you'll get line-by-line errors pointing to exactly where the invalid style is located
Once you fix those inline style violations and ensure your boilerplate is correct, the parsing error should clear up!
内容的提问来源于stack exchange,提问作者Brendan

