Wikimedia Developer Support

Template vs Transclusion

Hello everyone,
I’m a new developer in MediaWiki, and I’m trying to create a template for my pages. (Excuse me for my English)
I read the documentation, and didn’t understand how to embed the template.
For example, if my template is a file that contains: “Hello world!”

  1. What extension do I save to the file? .html, .php?
  2. Should I create the “Template” folder and put there my file? For example Templates: HelloWorld
  3. On which pages can I insert this template?
    I try on php page, and can’t.(because of the double-curly parentheses)
  • I also saw that there is an existing template called: Template: Note
    I saw its usages and didn’t understand how to use it too :frowning:

(Another thing- I saw that there is an extension called SemanticMediaWiki that enable Transclusion.
My purpose for the template, is to create a data graph from the data in the mediawiki, and display it in every page I want. Is it better?)

Thanks for help,
Sofia

Transclusion is the act of using a template. Its unrelated to SemanticMediaWiki.

You don’t create templates on the server. Templates are pages on your wiki that start with Template:

For example, if you create a page at https://mywiki.com/wiki/Template:MyTemplate

You can then use it on a page by writing {{MyTemplate}}.

You should not be editing any files on the server when making templates. Everything to do with templates happens via the web interface.

In general, you should never edit or create any .php files. The only php file you should be editing is LocalSettings.php to adjust server settings (And sometimes, you may add extensions to the extensions subdirectory).

Thanks Bawolff for your reply.
From what I understand, you are saying that using a template is only through the interface on the site.
You also wrote:

“You can then use it on a page by writing {{MyTemplate}}.”

Did you mean by the editing the page on the site, too?
If so - it’s really not what I’m looking for. :confused:

The truth is, I actually added an extension to my extensions folder, and I saw it in the “special pages” page.
But now I want to embed this page, on existing wiki pages, so that the graph I created on my special page(my new extension) will appear on the pages I select.
Is there a way to do that?

And thanks again for your help.
Sofia.

Hi, yes there is, its just usually not called that on the software side so as not to confuse with the user side feature.

For special pages, if the special page subclasses the IncludableSpecialPage class, that’s all you need and you can include via syntax like {{special:myspecislpage}}.

However in modern mediawiki parser tags/functions are considered the preferred approach.

See https://www.mediawiki.org/wiki/Manual:Special_pages and https://www.mediawiki.org/wiki/Manual:Tag_extensions

Hi Bawolff ,thanks again for your reply!
1.The special page I created, inherited from specialPage and not from IncludableSpecialPage. So I’ll have to change that.
Then I need to insert {{special: myspecislpage}} through the site interface?
2. A.Thanks for the information about the parser tags / functions, I will definitely try it!
B. And another point I’m not sure about -
After I create the tag / function - do I have a way to embed it through the software side, rather than the userSide?
I’ll explain-
I work with a docker.
I pulled the media wiki image,so I do not have access to the pages through the IDE that I am working with, because they are in the container.
So how do I make changes to pages through the code?
Is it possible at all? Regardless of whether or not I use docker.

Thanks Bawolff
I really appreciate it. :blossom:
Sofia.

Yes, you can add stuff from the server side. How to do that depends on the precise details of what you want to add and where you want to add it. Generally this is accomplished via https://www.mediawiki.org/wiki/Manual:Hooks .For example https://www.mediawiki.org/wiki/Manual:Hooks/ParserBeforeStrip but which one you need will depend on what you are doing.

Hi Bawolff,
I really appreciate your help!
Wow, how much information I got … I was sure I’m going to use templates / transclusion, but since you wrote that using them is not on the server side, but via the web interface, I realized that I was wrong.
And then you led me to a solution I wouldn’t think of at all-hooks!
And suddenly in a second reading of the documentation - that makes sense! :smiley:
I’d love to check out the steps with you:

  1. First of all I need to choose eventHandler, like the ParserBeforeStrip
  2. Add it to the extension.json-

{
“Hooks”: {
“ParserBeforeStrip”: “MyExtensionHooks :: onParserBeforeStrip”
}
}

3.I’m not so sure now-
I need to implement that function. For example - implement onParserBeforeStrip.
But is MyExtensionHooks it my folder or page name?
If I understood correctly - this is the folder name, and my page name will be hook.php?
The truth is that I’m a little confused, because the link you sent me (https://www.mediawiki.org/wiki/Manual:Hooks/ParserBeforeStrip), says:

Called from: File (s): parser / Parser.php.

What is meant by?

  • My goal is to add a graph to be used for site navigation.
    Clicking on a node will lead to a specific wiki page.
    Do you have a recommendation on which hook to use? And where can I read more information on how to place it on my page?

Thank you very very much! :blossom:
Sofia.