Template:Center/doc

From Wiki.CoreyBlair.US
Jump to navigation Jump to search

{{#ifeq:doc |doc

    | 

{{#ifeq:show |show

|

        }}{{#if: |
         |   {{#ifexist:Template:Center
                  | [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  |
                 }}
        }}
    | 
   }}

A simple template to center-align content in tables and other places. Be aware that the center class is appllied to this template, which means every element within the template has its left and right margins set to auto. This may harm some templates.

Example

{{#if: ||+ {{{title}}}}} {{#if: |
Markup Renders as

}}{{#if: {{Center|Hello world!}}

{{Center|Hello world!}}
Hello world!
{{#if:Hello world!||}}
}}{{#if:  | 

}}{{#if:  | 

}}{{#if:  | 

}}{{#if:  | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}

To do this without a template, simply use the following code:

{{#switch:pair
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <div{{#if:class="center" style="width:auto; margin-left:auto; margin-right:auto;"| class="center" style="width:auto; margin-left:auto; margin-right:auto;"}}
}}{{#switch:pair
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:div|!--||>}}...
}}{{#switch:pair
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:div|!--|-->|</div>}}
}}

To center a table, see Help:TABLECENTER.

Table

Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:l|: |Left |{{#switch:

                        |  = Template:{{#if:left|Left|Center/doc}}
                        | #default = {{#if:left|Left|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:left|left|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:c|:  |Center |{{#switch:
                        |  = Template:{{#if:center|Center|Center/doc}}
                        | #default = {{#if:center|Center|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:center|center|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:r|:  |Right |{{#switch:
                        |  = Template:{{#if:right|Right|Center/doc}}
                        | #default = {{#if:right|Right|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:right|right|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}}
Header text
Left
Left
}} ||
Center
{{#if:Center||}} || {{safesubst:#ifeq:Right|Right
Right

}}

Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|: |Align |{{#switch:

                        |  = Template:{{#if:align|Align|Center/doc}}
                        | #default = {{#if:align|Align|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|:  |Align |{{#switch:
                        |  = Template:{{#if:align|Align|Center/doc}}
                        | #default = {{#if:align|Align|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|:  |Align |{{#switch:
                        |  = Template:{{#if:align|Align|Center/doc}}
                        | #default = {{#if:align|Align|Template:Center/doc}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}}
Header text
{{#switch: left left =
Left
right =
Left
center =
Left
{{#if:Left
}} #default = Error in Template:Align: the alignment setting "left" is invalid.

}} || {{#switch: center

left =
Center
right =
Center
center =
Center
{{#if:Center
}} #default = Error in Template:Align: the alignment setting "center" is invalid.

}} || {{#switch: right

left =
Right
right =
Right
center =
Right
{{#if:Right
}} #default = Error in Template:Align: the alignment setting "right" is invalid.

}}

See also