Marmot Manual

Chapter 10. Text and Structural Elements

Table of Contents

Text Elements
Structural Elements

Text and structural elements are added to a document's body using the MU_XML_Element::add_element() method. This method takes the following format:

$enclosing_element->add_element('element_to_add', array(attributes), 'content');

The first argument is the type of element to be created. The second argument, an array of attributes, is not required for some elements. In those cases, a null can be substituted. The third argument, the element's content, can be either a string or an array of strings or other elements:

$enclosing_element->add_element('element_to_add', array(attributes), array('content', another_element, 'more content'));

Sometimes it is necessary to create "un-enclosed" elements- elements with no parent. These are useful when you wish to include an element inside another element's content. For example, you might wish for a paragraph element to contain styled text or a link. The mu_make_element() function performs this role:

mu_make_element('element_to_add', array(attributes), 'content');

Its syntax is the same as the MU_XML_Element::add_element() method.

If you are familiar with HTML, you may notice that many of the following examples require more keystrokes than their HTML equivalents. In exchange for making a lot of extremely difficult tasks easy, Marmot makes some extremely simple tasks slightly more complicated in order to separate program logic from appearance.

Examples of all of these elements can be seen in the example "Text and Structural Elements" included with Marmot.

Text Elements

Text elements are elements that contain only text, links, or styles. They are not concerned with a document's structure.

Paragraph

The simplest text element is the paragraph. It is used to add a paragraph of text to a document.

$para = 'Magnus es, domine, et laudabilis valde: magna virtus tua, et sapientiae tuae non est numerus. et laudare te vult homo, aliqua portio creaturae tuae, et homo circumferens mortalitem suam, circumferens testimonium peccati sui et testimonium, quia superbis resistis: et tamen laudare te vult homo, aliqua portio creaturae tuae.'; $body->add_element('para', null, $para);

Link

The link element is used to add a hyperlink to a document.

Links can be inserted inline into other elements:

$para = array('Including ', mu_make_element('link', array('href'=>'http://www.muohio.edu/'), 'links'), ' within a block of text is fairly common.'); $body->add_element('para', null, $para);

The link's URL can be relative or absolute:

$body->add_element('link', array('href'=>'http://www.muohio.edu/'), 'a link'); $body->add_element('link', array('href'=>'index.php'), 'a relative link');

A target can be specified for a link:

$body->add_element('link', array('href'=>'http://www.muohio.edu/','target'=>'_blank'), 'a targeted link');

A link can be opened in a popup window:

$body->add_element('link', array('href'=>'http://www.muohio.edu/', 'title'=>'Visit the Miami University homepage','popup'=>array('name'=>'miami', 'width'=>'600', 'height'=>'500')), 'a popup link');

If Javascript is not available on the client's browser, the width and height attributes will not have any effect.

Style

The style element is used to apply a CSS style to text or another element. Style elements are almost always inserted using the mu_make_element() function:

$para = array(mu_make_element('style', array('class'=>'strong'), 'Strong'), ' or ', mu_make_element('style', array('class'=>'emphasis'), 'emphatic'), ' text add visual punch.'); $body->add_element('para', null, $para);

Marmot provides a few common styles:

  • strong

  • emphasis

  • error

  • sourcecode

The programmer can call on an additional application-specific CSS file. To do so, specify the CSS file in the application's calls to MU_Presentation::display():

$presentation->display(array('title' => 'Greeting', 'appname' => 'My First Marmot Application', 'stylesheet' => 'styles.css'));

Image

Images can be inserted into a document with the image element:

$body->add_element('image', array('source'=>'marmot.gif', 'caption'=>'Marmot says hello', 'alt'=>'the Marmot logo'));

Note: Marmot requires that all images have "alt" attributes. This attribute is meant to contain a text description of the image.

Break

The break element is used to insert a newline. Break elements are almost always inserted using the mu_make_element() function:

$para = array('Sometimes ', mu_make_element('break'), ' you need a', mu_make_element('break'), 'break.'); $body->add_element('para', null, $para);