Topic on Project:Support desk

Jump to: navigation, search
Lbillett (talkcontribs)

I'd like to display a template on every page that puts some small content just underneath the user menu using a span with CSS position:absolute element. I tried specifying it in Mediawiki:Sitenotice, which gets the content to the desired location, but it inserts a blank line above the article title (so for every page, the title is lower than the normal position). Is there another way to display the template or tweak the display to get around this? Thanks!

Bawolff (talkcontribs)

How important is the <span>. If you use <div style="position:absolute"> instead, it will probably not output the <p> tag, as div is a block element.

Lbillett (talkcontribs)

<span> isn't important. I tried using a <div style="position:absolute"> but it still seems to include the empty line before the article title.

Looking at the source code of the page, it seems to end up getting wrapped up in 3 divs. Is that a problem? (I'm pretty weak when it comes to page formatting).

<!-- sitenotice -->
<div id="siteNotice"><div id="localNotice" lang="en" dir="ltr"><div style="position:absolute;">output to display</div>
</div></div>
<!-- /sitenotice -->
<!-- firstHeading -->

It may not be a line break at all, but something seems to bump the article title down some if I use either a div or span. Source code of a page when sitenotice is empty doesn't include the 3 divs. the firstHeading in vector's screen.css doesn't seem to have any relative positioning specified.

Is there something else I can try?

88.130.76.239 (talkcontribs)

I guess the empty line still comes from MediaWiki:Sitenotice. You either have to actually delete the page or to place a single minus sign ("-") in that page in order to stop it being output. If you put anything else there, MediaWiki will output that text - possibly causing an empty line.

Lbillett (talkcontribs)

Could vector.php be modified to display the output of a template? It looks like I could maybe use the Article object to get the template content, then throw it at $wgOut->addHTML. Seems messy... and I'd much rather try to do it IN the wiki. I could maybe make a special extension to do it... though, I've never done anything but special pages and parser/tag functions. Can an extension just blast out html without being called from an article?

88.130.120.174 (talkcontribs)

Ahh, what you want is possible. It's all possible.

No need for an extension or for an additional article object of its own. Instead, check Manual:Hooks for a hook to use; especially those in the section "Skin" might be interesting. Then add your HTML code from inside the according hook.

What I have not fully understood, where you want your content to appear. Is it at the very top of the page, there where it also says "Create account", "Log in" or "My contributions"? In that case I would pick the hook "PersonalUrls".

Lbillett (talkcontribs)

Very interesting! Regarding location, the empty space just below 'PersonalUrls' was where I was hoping. Or even the area to the left of them. Or below the sidebar (really, where ever it ends up being easiest and not looking like crap or messing up normal page display. It's ). The template basically spits out a short line of text (or nothing) based on some conditions. In reading the manual, the PersonalUrls seem to be set up to display links only. I'd like to make a non-link, but I suppose having it link to the template would be fine.

Not having used hooks of this type before, where would I actually set the parameters? In localsettings? or in the skin php? SkinTemplateOutputPageBeforeExec looks like it might be a starting place? Thanks!

88.130.120.174 (talkcontribs)

With the PersonalUrls hook you can "only" output a link. Maybe you can leave out the link target, so that it does not actually link anywhere, but you cannot render wiki text inside that hook. You could check, if the special syntax of MediaWiki:Sidebar allows you to add what you want, but I don't know if it supports conditions.

In order to render wiki text, you must pick a hook, which gives you access to the article object or to the output object.

I think I would try like that:

Use the hook ArticleViewHeader, in there use global $wgOut; and then do a $wgOut->addWikiText('{{AdditionalHeader}}');. So add this to LocalSettings.php:

 $wgHooks['ArticleViewHeader'][] = 'addHeaderToPages';

 function addHeaderToPages( &$article, &$outputDone, &$pcache ) {
   global $wgOut;
   $wgOut->addWikiText('{{AdditionalHeader}}');
   return true;
 }

This adds the contents from the template page AdditionalHeader in your wiki to the output text. In the template you can then set the conditions and stuff as you need so that the template creates the desired output. You can also wrap the whole output into a div and then place that div with position: absolute; at the place you want it to show up.

Lbillett (talkcontribs)

That's BAD ASS! It works perfectly!! Thank you so much! It let me output the div exactly where I was hoping without impacting anything else. Cheers!

79.134.213.62 (talkcontribs)

How to make AdditionalHeader template precede article header?

Reply to "Display template on every page"