[Fixed] Get valid RSS by adding CDATA wrappers to RSS description elements

Submitted by Barrett on Tue, 08/25/2015 - 06:19
[Fixed] Get valid RSS by adding CDATA wrappers to RSS description elements

A couple weeks ago, I posted about a problem I was having getting RSS to validate because the description element contained HTML markup.

The solution turned out to be as easy as I expected, once I found the right place to look. The first place I went was the Views module, where I found views-view-row-rss.html.twig in the templates directory. "Perfect", I thought, "that's my boy." A quick edit later, followed by a couple cache clears and some head-scratching, I still wasn't seeing my change.

Turns out the Views template file is overridden by the Classy theme, of which Bartik (yes, I use Bartk) is a subtheme. What awesomeness is Classy adding to the Views template, not much that I can see*. But I digress.. Rather than hack core (because we all know what that leads to), I created my own subclass of Bartik, dropped my updated views-view-row-rss.html.twig file in there, and Viola! Valid RSS

W3C Valid RSS logo

* Diffing the Views template and the Classy template


diff ./docroot/core/modules/views/templates/views-view-row-rss.html.twig ./docroot/core/themes/classy/templates/views/views-view-row-rss.html.twig
4c4
  * Theme override to display an item in a views RSS feed.
23,25c23,25
{{ item.value }}
---
>      {% if item.value -%}
>   >{{ item.value }}
27c27
' }}
---
>   {{ ' />' }}
Barrett Tue, 08/25/2015 - 06:19