4

In the DXA Reference Website the Entity views have the following HTML helper:

 <article class="rich-text @Model.HtmlClasses" @Html.DxaEntityMarkup()>

Output:

{prefix="s: http://schema.org/" typeof="s:Article" data-xpm="36"}   System.Web.Mvc.MvcHtmlString

Looking into the source and the output, I assume this is for:

  • Schema.org
  • XPM

Is it common practice to always use this helper on the opening <div> tag of every Entity view? Any exceptions or times I would not want to use it?

1 Answer 1

5

The HtmlHelperExtensions.DxaEntityMarkup method is documented as: "Generates semantic markup (HTML/RDFa attributes) for the current Entity Model."

Indeed, its main purpose is to render semantic markup, but as you noticed, it is also used for XPM markup. Note that XPM markup is currently not in the form of HTML attributes, but an HTML comment within the container element. As you see, it is initially rendered as an attribute which is later transformed into an HTML comment.

Note that "semantic markup" is broader than "Schema.org". In general, it outputs the semantics of the View Model (in RDFa format). You see a separation of concerns here: the View Model may have (public) semantics, the View itself doesn't know about those, but only knows where semantic attributes (if any) should be output. Similarly, the XPM markup may or may not be output (depending on whether the target is XPM-enabled), but the View doesn't contain that conditional logic.

So: yes, you should put @Html.DxaEntityMarkup() on your HTML element representing an Entity, regardless whether your View Model has public semantics; it acts as a placeholder for semantic markup and XPM markup.

UPDATE (answer to Jan's question)

Note that Schema.org only defines a standardized Vocabulary/Ontology (types, properties and relationships), not a specific way to refer to those types/properties. Quote from the Schema.org home page: "Schema.org vocabulary can be used with many different encodings, including RDFa, Microdata and JSON-LD".

RDFa, in contrast, does not define a vocabulary, but does define how to refer to semantic types/properties using XML/HTML attributes. It was originally intended for use in XML (e.g. XHTML 2), but has been adopted in HTML 5 too.

DXA outputs RDFa compliant semantic markup. This can use the Schema.org vocabulary (see View Models from Core Module), but can also use any other vocabulary; it depends on the semantic annotations on your View Models.

2
  • Interesting! Never realized that DXA uses RDFa. I think schema.org uses RDFa. Does the DXA markup stick to schema.org and in that way is using RDFa? Or does DXA use RDFa in a way that is not fully compliant to schema.org?
    – Jan H
    Commented May 6, 2017 at 10:35
  • My answer to that question was too long for a comment. :-) Updated the original answer. Commented May 6, 2017 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.