Template talk:Divbox

From IcehouseOrg
Jump to: navigation, search


divbox, from [1]

Divboxes on wikipedia look a little different than here. Why?


Wikis abound in boxed text, often templates.

Boxes may not always be appropriate; they can be obtrusive. But when boxes are used, they are generally formatted ad hoc. This leads to inconsistencies.

{{divbox}} provides a straightforward method of presenting any text within a box. Colors are selected using a private style keyword, which sets both box border and background, already chosen to work together, in a visual sense.

The keyword none puts your content inside an invisible box. This is available to offer the identical box model for your content, without a visible box.

This template may be used within another template; or as part of another page.


This template takes its first parameter and uses it to construct an instance of one of its component templates; this emulates a case statement. New divbox styles may be created with minimal effort. All of the (component) templates {{divstylekeyword}} contain only the style parameters of the box.

A <div> is generated with class="boilerplate metadata" and id=(second parameter); thus id is the same as the displayed title. A user's CSS may override the entire class.



  • keyword: private style keyword; chooses colors for box
  • title: plain text; appears strong and centered at top
  • content: any text, including markup; your content
What you see What you type
{{divbox|gray|Lorem ipsum|Lorem ipsum dolor...}}
{{divbox|red|Lorem ipsum|Lorem ipsum dolor...}}
{{divbox|navy|Lorem ipsum|Lorem ipsum dolor...}}
{{divbox|amber|Lorem ipsum|Lorem ipsum dolor...}}
{{divbox|none|Lorem ipsum|Lorem ipsum dolor...}}
{{divbox|navy||Lorem ipsum dolor...}}
  • Don't forget to close the template with double braces ("}}")!
  • If you want to omit a centered title for the box, you must use two pipes ("||") instead of one before your box content. Still, it is not recommended that you omit any title.
  • You must always supply the first parameter. This is a private style keyword from the list:

Remember these are private style keywords, not HTML colors. You must use lowercase only. The keyword none puts your content inside an invisible box.

Using subst: with this template

The subst: atom may be used with {{divbox}}. This may be highly desirable. Note that subst: does not take effect in preview, but only after saving a page. The template's inclusion is replaced by the code of the template itself, which will continue to write the box as before, but without an additional server call.

Since {{divbox}} itself calls a template based on your choice of style keyword, you will find that even after saving an instance of use with subst: there remains a "live" call to the underlying style template. This means that viewing the page risks a server call to the style template, but also means that changes to the style template automatically propagate to all pages where it is used. This way, all {{divbox}}-type boxes, wherever they are in the project, keep the same consistent look.

There are few restrictions on the content you may place within {{divbox}}. Just paste in your content and, when you're finished, be sure to close the template call with }}. However, if you put very long content in the box, or content that includes template calls, you may run into some trouble, because {{divbox}} cannot tell where its last parameter ends.

This template was designed for the display of relatively short messages, but if you want to box long or complicated content, insert this code in your page first:


That is, choose your style and title as usual (or omit the title with two pipes), but instead of actual content, write "DUMMYCONTENT". Then, save the page and reopen it for editing. You'll see the box code in all its gory detail, and the placeholder DUMMYCONTENT, followed by the HTML division closing tag. Now, you may simply replace DUMMYCONTENT with your content, save, and move on. Since almost anything may be placed within division tags, this should not break no matter what you do.

Making new divbox styles

I'd rather hope you were able to find joy within the existing set of styles, but if not, you can create new ones. Follow these instructions to be sure your new style will "play nice" with {{divbox}}. Note that this requires some understanding of CSS.

1. Experiment in a drawing program, such as GraphicConverter or Adobe Photoshop, and decide what colors you want for your new box style. You need to find out the HTML color codes for each color.

2. Open an existing box style template, such as {{divstylered}}. Copy out the code.

3. Create a new box style template page. It must be located in main Template namespace and must be named Template:divstyleXXXXX, where "XXXXX" is your new style name.

4. Paste in the "borrowed" code and replace the color codes with your new, chosen colors. Save the new template.

5. Return to this Talk page and add your new style to this documentation. Remember, a job's not over until the paperwork is done!

Note that you may even change the division box margins and paddings. This is not recommended. There are a couple of good reasons for specifying these values, and in these units. Most users who "roll their own" make choices with unintended consequences; {divbox} is meant to help you avoid these pitfalls.

Templates failing

Starting around 25 or 26 June, a class of templates (including divbox) began to format incorrectly. In the case of divbox, the color and frame disappeared. You can see the same bug affecting a different template on Talk:Sandbox/Zendo-Tao#Pyramid_census in the pyramid census section, in which the colors have vanished from the template markers adjacent to the images. So far, this bug doesn't seem to affect anything except for templates which use other templates to select formatting. This bug is probably not related to the other ongoing site problems.

Technical info

MediaWiki seems to be mis-using the templates within the divbox template, as this bit of the HTML shows:

  <td><div class="boilerplate metadata" id="&#123;&#123;&#123;2}}}"
  style="&#123;&#123;divstyle&#123;&#123;&#123;1}}}}}"><div class="center">

All of those "&#123;" tokens are left curly braces, which should have been replaced with parameters or templates, rather than output with the HTML. On Wikipedia, which has the same version of MediaWiki, divboxes still work fine; so it may or may not be a bug in MediaWiki, but a bug report there may help us to get this fixed. (PHP is another likely culprit, so you could file a report there, too.) Unless something else changed on the site in the past day or so.... — Rootbeer (Tom) (U | T | C) 22:20, 26 Jun 2005 (GMT)

I don't know whether this problem is still occurring or not. Since this bug report was written, the wiki has been migrated to a new host (and some mojibake occurred in the process, meaning there are a lot of other problems on the linked-to page), and then I've had to dump and restore the whole wiki. So, if this is anything we still need, please check to see if the problem still exists and let me know if it does. — λ (talk | contribs) 16:44, 6 November 2016 (PST)