logo

MMBase tips

Display a node

tip #12 / Mon 3 May 2010 / André / 1 comments

An example of a template with just one node. The ancient mmbase MyNews magazine made even simpler.

MyNews is the most used example in all mmbase releases: it is a magazine with the very first five newsarticles that featured on a former version of www.mmbase.org. This is the complete copy-and-paste-example in jspx:

<mm:content 
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:mm="http://www.mmbase.org/mmbase-taglib-2.0"
expires="120" postprocessor="none" type="text/html">
<jsp:output omit-xml-declaration="true" />
<mm:cloud>
<html>
<head>
<title>MyNews example</title>
</head>
<body>

<mm:node number="default.mags">
<h1><mm:field name="title" /></h1>
<p><mm:field name="intro" /></p>
<p><mm:field name="body" /></p>
</mm:node>

</body>
</html>
</mm:cloud>
</mm:content>

Which prints in HTML5 fasion (that's why I used the <jsp:output omit-xml-declaration="true" /> declaration):

<html>
<head>
<title>MyNews example</title>
</head>
<body>
<h1>MyNews magazine</h1>
<p>This MyNews magazine is an example of news articles in a
magazine.</p>
<p>This magazine shows a news article magazine. The news articles are
from the MMBase.org web site. This magazine contains news articles but
it is also possible to create other magazines like: sport magazine,
economics magazine, etc. The articles in this example are related to
urls, and an author. While creating your own magazine you are free to
relate it to other information. Explore this MyNews magazine and take a
look at the templates. We hope that it will inspire you to create much
better magazines ;-)</p>
</body>
</html>

Without all the frills of including the <mm:content />, <mm:cloud /> and the <jsp:output omit-xml-declaration="true" /> tag, displaying the magazine node boils down to just the part with the <mm:node /> tag and its fields:

<mm:node number="default.mags">
<h1><mm:field name="title" /></h1>
<p><mm:field name="intro" /></p>
<p><mm:field name="body" /></p>
</mm:node>

The magazine node has an alias named 'default.mags'. In mmbase you can asign aliasses to nodes which makes them exportable to other mmbase instances. This alias translates to the node number of MyNews Magazine which is retrieved from mmbase and of which the fields title, intro and body are printed.

1 comment

I would go for:
<mm:field name="intro" escape="p" />
<mm:field name="body" escape="p" />

These things typically produce more then one paragraph. The escaper 'p' converts empty lines to paragraphs (among a few other things).

ma 3 mei 2010 / mihxil → http://www.meeuw.org

RSS feed

Tweet this article

Most mentioned links:

MMBase documentation
MMBase API
MMBase SVN
Bugtracker
MMBase Taglib reference
The reference for all tags mm