HTML Head

Last modified by slauriere on 2019/06/06

Adds content to the HTML "head" tag of all wiki pages

Usage

The extension point adds the provided content to the page HTML head element. It is typically useful for adding HTML metadata to pages. 

It was introduced in version 11.1RC1 with the identifier org.xwiki.platform.head and was later changed to org.xwiki.platform.html.head in 11.5.

The screenshot below illustrates an example of metadata tags injected into the HTML head using this extension point. The second one shows the code used by a User Interface Extension (UIX) to produce such content.

html-head-extension-example.jpg

Such custom metadata tags can be produced by the following code sample, copied from the OpenGraph application.

{{velocity}}
{{html clean="false"}}
#set ($serverUrl = $xcontext.URLFactory.getServerURL($xcontext.context))
#set ($hasImages = false)
#macro(addOpenGraphTagsForAttachedImages $pageReference)
  #set ($page = $xwiki.getDocument($pageReference))
  #foreach ($attachment in $page.attachmentList)
    #if ($attachment.isImage())
      #set ($hasImages = true)
      #set ($path= $page.getAttachmentURL($attachment.filename))
      <meta property="og:image" content="$serverUrl$path" />
    #end
  #end
#end
<meta property="og:url" content="$doc.externalURL"/>
<meta property="og:type" content="article" />
<meta property="og:title" content="$tdoc.getRenderedTitle("plain/1.0")" />
## Add all current page's image attachments as "og:image".
#addOpenGraphTagsForAttachedImages($doc.documentReference)
## If current page has no attached image, add the ones of the home page, if any.
#set ($wikiDescriptor = $services.wiki.getById($xcontext.wiki))
#if (!$hasImages && $wikiDescriptor && $doc.documentReference != $wikiDescriptor.mainPageReference)
  #addOpenGraphTagsForAttachedImages($wikiDescriptor.mainPageReference)
#end
{{/html}}
{{/velocity}}

Definition

This Extension Point is contributed by this extension and was added in version 11.1-rc-1 of that extension.

Category
HTML
Extension Id
org.xwiki.platform.html.head
Content to be provided

The content to be added in the HTML head tag of all wiki pages.

Parameters to be provided

Order: used for ordering the extensions.

Example

This extension point is used by the OpenGraph application.

Tags:
Created by slauriere on 2019/02/05
   

Get Connected