Fact Boxes

From FundaWiki

Jump to: navigation, search

Factboxes can be handled in two ways in the index.php template file.

First we can start by displaying all factbxoes on the current page.

   <?php
   
   $flayout = "
   <div class=\"factbox\">
       <h4>HEADER</h4>
       IMGLINK
       <p>
           CONTENT
       </p>
   </div>
   ";
   
   $keys = array(
     "[PDF]" => "<img src=\"/fundanemt/site_graphics/mime-pdf.png\" alt=\"PDF File\">",
     "[PS]" => "<img src=\"/fundanemt/site_graphics/mime-ps.png\" alt=\"Postscript File\">",
   );
   
   $parser->printFactBox($flayout, $keys);
   
   ?>

The first argument to the printFactBox() method is the layout of a factbox. In this example it consists of a div box with a header and a content paragraph + a image if an image is inserted into the factbox in the page editor.

The second argument is optional and contains a list of keywords and what they should be replaced with in the factbox. On fundanemt.com we replace the keyword CODELINES with the output from a PHP-function to display the number of lines of code in the fundanemt development tree.

   <?php
     // We only want to have LINECODE available on frontpage.
     if ($parser->ID == 1) {
       $keys = array(
         "LINECODE" => codelines()
       );
     }
     $parser->printFactBox($flayout, $keys);
   ?>

In the first example with [PDF], which is used on (http://qte.dk/study/3semester/) replaces [PDF] with a nice looking icon.

Checking if page contains factboxes

It is possible to check if a page contains any factboxes, and this can be used to use the space that factboxes normally orcupy in the layout to other page content.

   <?php
     if ($parser->hasFactBox()) {
       $parser->printFactBox($flayout, $keys);
     }
   ?>
Personal tools