Line 27: | Line 27: | ||
<p>Note: Using HTML in MediaWiki pages will cause the final page (as fully rendered by MediaWiki) to be noncompliant with strict HTML formatting specifications. This is basically inevitable, and is an acceptable trade-off for the added flexibility in wiki design that you get by using HTML. Most modern web browsers will interpret pages in "quirks" mode, which tries to "do the right thing" with HTML that is not strictly compliant.</p> | <p>Note: Using HTML in MediaWiki pages will cause the final page (as fully rendered by MediaWiki) to be noncompliant with strict HTML formatting specifications. This is basically inevitable, and is an acceptable trade-off for the added flexibility in wiki design that you get by using HTML. Most modern web browsers will interpret pages in "quirks" mode, which tries to "do the right thing" with HTML that is not strictly compliant.</p> | ||
+ | |||
+ | |||
+ | </div> | ||
<a id="link-and-script"></a> | <a id="link-and-script"></a> | ||
<div class="clear"></div> <div class="clear"></div> | <div class="clear"></div> <div class="clear"></div> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <div class="oneColumn"> | ||
<h2>How to use <link> and <script> tags to include CSS and Javascript</h2> | <h2>How to use <link> and <script> tags to include CSS and Javascript</h2> | ||
<p>To use this method, create a page whose name starts with "Template:YourTeamName" and enter your CSS or Javascript code <b>without any surrounding <code><html></code> tags:</b></p> | <p>To use this method, create a page whose name starts with "Template:YourTeamName" and enter your CSS or Javascript code <b>without any surrounding <code><html></code> tags:</b></p> | ||
+ | |||
+ | </div> | ||
+ | <div class="twoColumns"> | ||
+ | |||
<b>2015.igem.org/Template:YourTeamName/CSS</b> | <b>2015.igem.org/Template:YourTeamName/CSS</b> | ||
Line 45: | Line 57: | ||
}</pre> | }</pre> | ||
+ | |||
+ | </div> | ||
+ | |||
+ | <div class="twoColumns"> | ||
<b>2015.igem.org/Template:YourTeamName/Javascript</b> | <b>2015.igem.org/Template:YourTeamName/Javascript</b> | ||
<pre> | <pre> | ||
Line 50: | Line 66: | ||
alert(x); | alert(x); | ||
}</pre> | }</pre> | ||
+ | |||
+ | |||
+ | </div> | ||
+ | |||
+ | |||
+ | <div class="oneColumn"> | ||
<p>Then, include these pages using <code><link></code> tags for CSS, and <code><script></code> tags for Javascript:</p> | <p>Then, include these pages using <code><link></code> tags for CSS, and <code><script></code> tags for Javascript:</p> |
Revision as of 18:21, 18 December 2015
HTML versus MediaWiki markup
All the iGEM web sites are built on top of MediaWiki, which allows groups of people to create and edit pages easily.
MediaWiki has its own markup for formatting pages, creating links, etc. However, using HTML allows more creativity and flexibility. iGEM's websites allow any HTML tags. Simply enclose your HTML inside <html>
tags within the page text.
You can mix wiki markup and HTML on the same page. Just make sure all the HTML is inside <html>
tags, and all the wiki markup is outside <html>
tags.
Example:
== A page including both wiki markup and HTML == This page uses ''wiki markup'' for part of the text, and ''HTML'' for another part. <html> <p>Here is an HTML paragraph with <i>italic text</i> in it.</p> </html> And there's more '''wiki markup''' at the bottom of the page!
Note: Using HTML in MediaWiki pages will cause the final page (as fully rendered by MediaWiki) to be noncompliant with strict HTML formatting specifications. This is basically inevitable, and is an acceptable trade-off for the added flexibility in wiki design that you get by using HTML. Most modern web browsers will interpret pages in "quirks" mode, which tries to "do the right thing" with HTML that is not strictly compliant.
How to use <link> and <script> tags to include CSS and Javascript
To use this method, create a page whose name starts with "Template:YourTeamName" and enter your CSS or Javascript code without any surrounding <html>
tags:
div.classname { border: 1px solid green; } #id { color: red; }
function f(x) { alert(x); }
Then, include these pages using <link>
tags for CSS, and <script>
tags for Javascript:
<html> <link rel="stylesheet" type="text/css"
href="https://2015.igem.org/Template:YourTeamName/CSS?action=raw&ctype=text/css" /> <h2>Our Project</h2> <p>Here is the beginning of the page about our project.</p> <p>Here is the end of the page about our project.</p> <script type="text/javascript" src="https://2015.igem.org/Template:YourTeamName/Javascript?
action=raw&ctype=text/javascript"></script> </html>
Strictly speaking, this is an incorrect use of the <link>
tag. But as stated previously, using HTML on MediaWiki will already result in not-quite-compliant pages that still render correctly in most browsers. It is not really worthwhile to worry about this.
How to make "inline" CSS and Javascript
You can include CSS or Javascript within <style>
or <script>
tags in your HTML. It is customary to put CSS styling at the beginning of your page (before the main content), and Javascript code at the beginning or the end.
NOTE: If you use inline Javascript, you cannot use the && operator. When the page is rendered, any & will be encoded to &. For short scripts, you can get around this problem by using nested if
statements instead of &&. However, you should use <script> tags to include any substantial scripts.
<html> <style type="text/css"> h2 { color: red; } /* ... more CSS here ... */ </style> <script type="text/javascript"> var foo = 3; // ... more Javascript here ... </script> <!-- Main content of the page starts here --> <h2>This text will be red</h2> <p>This text will be the normal text color</p> <!-- Main content of the page ends here --> <script type="text/javascript"> var a = 1; var b = "apple"; /// ... more Javascript here ... </script>
How to use templates including CSS and Javascript
If you want to use the same styles or scripts on several different pages, it is useful to write them in one place and then "include" them on your individual pages. One way you can do this is to use MediaWiki's Template function.
Create a page whose name starts with "Template:YourTeamName". Inside <html>
tags, put the material you want to include:
<html> <style type="text/css"> h2 { color: red; } </style> </html>
Then, use MediaWiki's syntax to include the template on another page, outside the <html>
tags:
{{YourTeamName/CSS}} <html> <h2>Our Project</h2> <p>Here is the beginning of the page about our project.</p> </html> {{YourTeamName/A_template_that_goes_in_the_middle_of_the_page}} <html> <p>Here is the end of the page about our project.</p> </html> {{YourTeamName/Javascript}}
You can include any HTML content this way, not just CSS and Javascript. This is useful for creating things like a common header, menu bar, and footer for the pages on your wiki.
If you edit a page, there will be a list of which templates are used on that page, below the Save/Preview buttons.
You can also see which pages use your template. Go to the template, and then look in the top menu for "Wiki Tools" → "What Links Here". This is useful if you want to change or delete a template -- you can check if any important pages are using it.
NOTE: If you make a template containing Javascript, you cannot use the && operator. When the page is included via the {{ ... }} syntax, any & will be encoded to &. For short scripts, you can get around this problem by using nested if
statements instead of &&. However, you should use <script> tags to include any substantial scripts.