How to use For

Článok doteraz nikto nepreložil. Pripojte sa k nám a pomôžte ho preložiť!

One of the great features of our Knowledge Base is the ability to show instructions customized for operating systems (Windows, Android, etc.) and Firefox versions. We can say, for example, that a certain section of a help article is "for" Windows users and Mac and Linux users won't see it. The feature is designed to work invisibly. When someone opens a help article, we'll automatically detect what operating system and version of Firefox they are using and show the appropriate instructions. This article goes over the details of how to use {for} in Knowledge Base articles.

How to switch instructions to different operating systems or Firefox versions

In order to follow the example in this article, you'll have to switch the article selector to different operating systems and Firefox versions. It's located at the top of the article.

Article Selectors

Basic syntax and behavior

Operating Systems

Here is the syntax to show an image for Windows 7/Vista:
{for win7}[[Image:vista.jpg]]{/for}

  • Change the selector to Windows 7/Vista to see the image:

    vista.jpg
  • If you change the selector to Windows XP, Windows 8, Mac OS X or Linux, the image above won't be shown because it's not "for" them.

Although the Windows selector doesn't exist, you can write instructions that apply to all Windows versions:
{for win}[[Image:Windows Logo]]{/for}

  • Change the selector to Windows XP, Windows 7/Vista, or Windows 8 to see the image:

    Windows Logo
  • If you change the selector to Mac OS X or Linux, the image above won't be shown because it's not "for" them.
Note: If you change the selector to Android the image is visible even though it isn't specified. That's because we default to showing Windows 7/Vista instructions (unless otherwise specified) if you are using Firefox on Android. We also default to showing Android instructions if you are looking at the Firefox for Android website with Windows, Mac or Linux.

Firefox versions

Here is the syntax to show something for Firefox 22 and above:
{for fx22}[[Image:Firefox Logo]]{/for}

  • Change the selector to Firefox 22 or higher to see the image:

    Firefox Logo
  • If you change the selector to Firefox ESR the message above will disappear because it's not "for" that version (Firefox ESR is currently based on Firefox 17).

Show instructions for only one version of Firefox

To show instructions only for Firefox 22, use the "=" operator:
{for =fx22}[[Image:Firefox Logo]]{/for}

  • Now the image only shows when you change the selector to Firefox 22:

    Firefox Logo

Combining operating systems & Firefox versions

You can specify an operating system and a Firefox version by separating them with a comma:
{for win,fx22}[[Image:Windows Logo]][[Image:Firefox Logo]]{/for}

  • Change the selector to Windows and Firefox 22 or higher to see images:

    Windows Logo Firefox Logo

A more complex situation with an implied "or" can be written like this:
{for mac, winxp, win7, =fx17, fx22}[[Image:Windows Logo]][[Image:macos.jpg]][[Image:Firefox Logo]]{/for}

  • Change the selector to Mac or Windows XP or Windows 7/Vista and Firefox ESR or Firefox 22 and above to see images:

    Windows Logo macos.jpg Firefox Logo


Formally, the markup between {for} and {/for} will be shown if either of these conditions is met:

  • The {for} lists at least one OS and includes the one the user is running (or has manually selected).
  • The {for} lists at least one Firefox version and includes the one the user is running (or has manually selected).

Otherwise, the contents of the {for}…{/for} is not shown.

A few other things to note:

  • Spaces after the commas are optional.
  • The {for} syntax only works on Firefox Knowledge Base articles.
  • {for} and other wiki markup doesn't work in article search summaries.
  • Headings which are hidden by {for} blocks do not appear in the page's table of contents. If the user causes them to show by manually selecting the right OS/browser combination, the table of contents entries instantly appear.

Operating system and browser abbreviations

These are the operating system and browser abbreviations available for use with {for}:

  • win (Windows)
  • winxp (Windows XP/2000/Server 2003)
  • win7 (Windows 7/Vista/Server 2008)
  • win8 (Windows 8/8.1/Server 2012)
  • mac (Mac OS X)
  • linux (Linux)
  • android (Android mobile OS)
  • fxN where N = the Firefox version, i.e. fx22, fx23, fx24, etc.
  • mN where M = the Firefox version, i.e. m22, m23, m24, etc.
Note: Every six weeks we add support for the latest beta version of Firefox. At the same time we remove the oldest version from the selector but the old markup will still work. So, for example, if someone views an article with Firefox 12 they will see instructions for their version (see this thread to know which versions are no longer supported).

Inline and block-level contexts

{for} can be used in both inline and block-level contexts (in the HTML sense). The inline form takes effect when working within a line of text:

This is {for win}inline use{/for}.

The block form is used to wrap entire paragraphs, ordered lists, headings, and so on. The only caveat is that, when using the block form, the {for} and {/for} should each be on a line by itself. Otherwise, it might be considered part of a neighboring paragraph and produce surprising results.

{for win}
This is block-level.
*One
*Two
{/for}

Using the {for} snippet in the autocomplete list

If you don't remember the syntax when writing an article, just press Ctrl + Space barcommand + space bar when the syntax highlighting is turned on and select for snippet in the autocomplete list. You will be presented the following pattern: {for os_or_firefox_version}text{/for}. Replace the stubs by what you want and you're done.

Using the handy dandy {for} button in the article editor

When you're editing a Knowledge Base article you can use the {for} button in the toolbar to write the markup for you.

  1. Highlight the text you want to put {for} tags around.
  2. Click Show for… in the editing toolbar.
  3. Check the boxes next to the Firefox versions and operating systems that you want to see this piece of content and then click Add Rule. The customized {for} tags will be placed around the section you highlighted.

Best practices for using {for} in articles

When writing instructions for different operating systems, it's best to write complete sentences and paragraphs for each OS/Firefox version even if it means duplicating things. This makes the article easier to understand, maintain and localize. When it comes time, for example, to remove specific instructions for Firefox 6 and below, those sections can just be deleted rather than trying to excise them from a larger section.

Example:
Bad
#{for win,linux}At the top of the Firefox window{/for}{for mac}On the menu bar{/for}, click on the {for fx35}{menu Tools}{/for}{for mac,linux,fx4}{menu Tools}{for win,fx4}{menu Firefox} menu, go over to the {menu History} menu and select {menu Clear Recent History…}{/for}{for not win,fx4} menu, and select {/for}{for win,fx35}{menu Clear Recent History…}{/for}{for mac,linux}{menu Clear Recent History…}{/for} {for win,fx4}<br>'''For Windows XP:''' At the top of the Firefox window, click on the {menu Tools} menu and select {menu Clear Recent History…}{/for}

Good
{for fx4}
#{for win}At the top of the Firefox window, click on the {menu Firefox} menu, go over to the {menu History} menu and select {menu Clear Recent History…} ('''Windows XP:''' Click on the {menu Tools} menu and select {menu Clear Recent History…}).{/for}{for mac}On the menu bar, click on the {menu Tools} menu and select {menu Clear Recent History…}{/for}{for linux}At the top of the Firefox window, click on the {menu Tools} menu and select {menu Clear Recent History…}{/for}
{/for}
{for fx35}
#{for win,linux}At the top of the Firefox window, click on the {menu Tools} menu and select {menu Clear Recent History…}{/for}{for mac}On the menu bar, click on the {menu Tools} menu and select {menu Clear Recent History…}{/for}
{/for}

Another example:
In the example below, we treat Firefox 20 and below, Firefox 21/22, and Firefox 23 and above as three different sets of instructions. That's often the case but more and more as we change Firefox every six weeks we'll see more changes in later versions. They'll look like this:

Good:
{for not fx21}
#The old instructions.
{/for}
{for =fx21,=fx22}
#The new instructions.
{/for}
{for fx23}
#The NEW new instructions.
{/for}

Share this article: http://mzl.la/1b9SAhb

Pomohol vám tento článok? Čakajte prosím...

Títo skvelí ľudia pomohli s písaním tohto článku: AliceWyman, Verdi, scoobidiver, feer56, mephistofoles, rabbihossain. Vy môžete pomôcť tiež - prečítajte si ako.