Help:Sjablonen

Uit 3rail Wiki
Naar navigatie springen Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Warning2.png Dit is een copy/paste artikel van MediaWiki (Engelse versie)

In Bewerking !
Treinsmurf

Als je standaard teksten hebt die je wilt opnemen op meerdere pagina's, kun je de wiki-sjabloon-functie gebruiken.

Aanmaken

Sjablonen zijn standaard wiki-pagina's waarvan de inhoud voorzien is van tekst en afbeeldingen welke je kunt insluiten in andere pagina's. Dit kan zowel een nieuwe pagina als een bestaande pagina zijn. Sjablonen zijn in een specifieke categorie te vinden "Sjablonen:"Sjabloon:"Naam"".

Het simpelste gebruik van sjablonen is als volgt. Als u een pagina met de naam "Sjabloon: Welkom" met inhoud aanmaakt:

Hallo! Welkom op de wiki.

heb je je eerste sjabloon aangemaakt! Als u vervolgens de code: {{Welkom}} op een andere pagina gebruikt, zal wanneer op die pagina de tekst wordt bekeken "Hallo! Welkom op de wiki." te zien zijn in plaats van {{Welkom}}. De sjabloon inhoud is "ingesloten" in de andere pagina, dat wil zeggen deze is geïntegreerd in de pagina.

U kunt vervolgens {{Welkom}} op elk punt van elke pagina waar u wilt iemand verwelkomen. Stel dat het wordt gebruikt in 100 pagina's en u daarna de sjabloon inhoud verandert in:

Hallo Iedereen! Welkom bij deze prachtige 3rail-Wiki.

en vervolgens opnieuw een van de 100 pagina's bekijkt waarin de sjabloon werd gebruikt, ziet u de nieuwe tekst in plaats van de oorspronkelijke. Op deze manier heb je de inhoud van 100 pagina's veranderd, zonder ze te bewerken, omdat de sjabloon ingesloten wordt in deze pagina's.

Dit is de basis functie. Er zijn verschillende extra functies voor sjablonen om deze functie 
uit te breiden en maakt daardoor sjablonen zeer nuttig.

Gebruik van sjablonen

Sjablonen kunnen op andere pagina's op verschillende manieren worden gebruikt:

  • {{Naam}}, zoals boven omschreven, 'bevat' het sjabloon inhoud zoals opgeslagen in de pagina [[Sjabloon:Naam]])wanneer de pagina met het sjabloon wordt opgehaald en weergegeven. Dit betekent tevens dat als het sjabloon later gewijzigd wordt, de vernieuwde inhoud van de "ingesloten" pagina eveneens automatisch gewijzigd zal worden.
Dit kan voordelen hebben echter niet als de pagina waar de sjabloon inhoud is opgeslagen niet 
gewijzigd mag worden met deze vernieuwde inhoud. Bijv. bij sjablonen met voorbeelden van 
wiki artikel-pagina's.
  • {{subst:Naam}}plaatst die string met de inhoud van het sjabloon in de bron van de ingesloten pagina. Bij het opslaan van deze pagina kan daarna de sjabloon-inhoud normaal gewijzigd worden (edit) los van de inhoud van het oorspronkelijke Sjabloon.

Controle sjabloon inclusion (insluiten)

Standaard wordt de gehele inhoud van een sjabloon verwerkt en weergegeven zowel wanneer de sjabloon pagina rechtstreeks bekeken wordt als wanneer het sjabloon opgenomen wordt in een andere pagina. U kunt echter dit opnemen beheersen door het gebruik van <noinclude> en <includeonly> tags.

Alles tussen <noinclude> en </noinclude> zal getoond worden als de sjabloon pagina "direct" bekeken wordt en niet getoond wanneer het niet ingesloten is in een andere pagina. De bedoeling van deze toepassing is om dingen aan de sjabloon pagina te doen die niet hetzelfde zijn als in een andere pagina waarvan de sjablooninhoud ingesloten wordt:

  • Specifieke tekst voor gebruik van het sjabloon..

Tot zover "vertaald" en aangepast voor 3rail-wiki gebruik

  • [[Help:Categories|Categoriseren] van het sjabloon.
  • Categoriseren van pagina's waar het sjabloon ingesloten is.. Note that when you change the categories applied by a template in this fashion, the categorization of all the pages where that template is included may not be updated until some time later: this is handled by the {{mediawiki|Manual:Job queue|job queue}}. To force the re-categorisation of a particular page, open the page for edit and save it without changes.
  • Ensuring that the template's code is not executed when viewing the template page itself. Normally this is because it isn't receiving any parameters and its execution without parameters has an undesired aspect.

Of course, everything outside <noinclude> and <includeonly> tags is processed and displayed both when the template page is being viewed directly and when the template is being included in another page.

Organizing templates

For templates to be effective, users need to find them, and find out how to use them.

To find them, users can:

  1. Click Special Pages > All Pages
  2. In the Namespace list, choose Template and click Go.

To give usage information, include an example like this one on the template page:

<noinclude>
== Usage ==
Welcome users:
{{Thankyou|reason=your reason|signature=your signature}}
</noinclude>

Then, an editor can simply copy and paste the example to use the template.

Copying from one wiki to another

you'll need system admin access to the server of your MediaWiki instalation.

Templates often require CSS or other templates, so users frequently have trouble copying templates from one wiki to another. The steps below should work for most templates.

Extensions

you'll need system admin access to the server of your MediaWiki instalation.

An extension often used in templates is ParserFunctions. Visit page {{mediawiki|Help:Extension:ParserFunctions|ParserFunctions}} and check if any of the functions listed there are used in the templates you've copied. If so, you have to install the {{mediawiki|Extension:ParserFunctions|ParserFunctions extension}}. To install it, you'll need system admin access to the server of your MediaWiki instalation.

CSS and JavaScript code

you'll need system admin access to the server of your MediaWiki instalation.

Besides MediaWiki code, many templates make use of CSS and some rely on JavaScript to work fully. If the copied templates are not behaving as expected, this may be the cause. To copy the required CSS and JavaScript to your wiki you'll normally need to have admin priviledges, because you'll be editing system messages in the "MediaWiki:" namespace.

  1. Look for the use of CSS classes (text like class="foobar") in the template text. If those classes appear in "MediaWiki:Common.css" or "MediaWiki:Monobook.css" on the original wiki, copy them to "MediaWiki:Common.css" on the new wiki and check if the template is now fine.
  2. If the copied template is still not working as expected, check if there is code in "MediaWiki:Common.js" or "MediaWiki:Monobook.js" on the original wiki. If so, you can try copying it to "MediaWiki:Common.js" on the new wiki. Normally, it is a good idea to only copy code from trusted sources, and first browsing the code to identify and select the parts that seem relevant. You may find comments that can serve as clues to identify the functionality of each part. When in doubt, copy all the code to the new wiki.

Specifying parameter defaults

you'll need system admin access to the server of your MediaWiki instalation.

Very often you will see parameters in this form:

{{{A template parameter|}}}

The pipe character "|" is the delimiter for a default value in the parameter. In the example above, it is empty, so the default would be an empty string if no value were passed from the template to the parameter. Of course, you may define a default like this:

{{{A template parameter|with a default value}}}

The string "with a default value" is the default value of the parameter if it is not set elsewhere.