Topic on Project:Support desk

Jump to navigation Jump to search

Meta tags in skin from MediaWiki template

Headshaker1 (talkcontribs)

Hi! I'm a little bit confused with interacting between template and skin.

Let's say i have a template in my MediaWiki like

 <div id="custom-person">
 * <span>Birthday:</span> {{#if: {{{birth date|}}} | <b>{{#ol-time:|{{{birth date}}}}}</b> | — }}
{{#if: {{{full name|}}} | * <span>full name:</span> <b>{{{full name}}}</b>}}
{{#if: {{{birth place|}}} | * <span>birth place:</span> <b>{{{birth place}}}</b>}}
{{#if: {{{age|}}} | * <span> age:</span> <b>{{{age}}}</b>}}
{{#if: {{{nationality|}}} | * <span> nationality:</span> <b>{{{nationality}}}</b>}}

<div class="clear"></div>





All these pages are in one Namespace (0).

I need to generate head meta tags with data from this template.

I figured out how to filter such a pages and add title tags in my SkinPerson.php

if ( $out->getTitle()->getNamespace() == 0 ) {
    $out->addMeta( "description", $out->getPageTitle());
    $out->addHeadItem( 'og:description', '<meta property="og:description" content="' . $out->getPageTitle() . '">');

But I'm really stuck on how can I insert in, say, 'og:description' tag something like {{{full name}}} + {{{age}}} ?

Thanks in advance!

TheDJ (talkcontribs)

wikitext templates are not simple key values, they are multilevel nested templating with logic that generates HTML. As such it is hard to retrieve the result of a parameter and reuse it elsewhere. Traditionally, we use parser functions like for instance #coordinates provided by Extension:GeoData. This parser function then is executing during the parsing of all the wikitext code of a page, extracts values and puts them into a storage location where it is reachable with database functions.

Then you reuse that information every time the page is rendered.

Maybe you should use something like Extension:Page Forms to store and retrieve your values. I suspect it will have some hooks that will allow you to retrieve the data in a hook so that you can add head items etc.

Ciencia Al Poder (talkcontribs)
Headshaker1 (talkcontribs)

Thank you! I'll try to solve it one of these ways

Jonathan3 (talkcontribs)

I use Extension:WikiSEO for this and suspect it would work for you too. I use it alongside Extension:Cargo but from memory it would work the same within any template.

Reply to "Meta tags in skin from MediaWiki template"