|
This is a reference guide aimed at fellow developers wanting to build stuff in InfoGlue. We have also just published the deliver engines javadoc which gives you a really good idea of what methods are available. For template builders - check out Basic Template Controller for InfoGlue 1.2 which is the $templateLogic-object and Component Logic for InfoGlue 1.2 which is the object to use mostly for components.
As the template language used are based on Apache Velocity you should take a look at their reference first if you are unfamiliar with the syntax we use in this reference. Further more this reference is all dedicated to building templates to represent a site. It has nothing to do with templates in the cms itself. It is the InfoGlue deliver that uses the templates, not the cms itself. What the InfoGlue platform gives you when building your templates is a couple of connection-points and functionalities that lets you reach contents and other entities in the cms. Velocity works in that way that you before processing put whatever data or logic you need in a pool of resources, which are then reachable from the template. We will focus on the logic supplied by the templateLogic-object, which the platform supplies by default. This object gives you most functionality you need which concerns getting content and structure from the cms.
The TemplateLogic Object
The templateLogic object is mainly a gateway to a lot of different functionalities, which are all important when, building a web page and connecting with the InfoGlue cms. We have grouped the kind of functionality into these categories:
Basic understanding Contents Digital Assets (Images/pdf:s and other binary files) Structure/Navigation Template reuse Application Integration Misc Examples
Basic understanding There are some important aspects that need to be understood before one can start building templates. The most central is page context. When a user asks for a page on your site all requests goes through one central distributor. If you take for example a typical request it might look like this:
http://localhost/site/ViewPage.action?siteNodeId=34&languageId=1&contentId=null
The ViewPage.action is the central distributor and it has a lot of functionality but right now we just focus on the ordinary page processing. What it does is checking which page the user requests and that is identified by the siteNodeId=34 in the URL above. The siteNodeId identifies a unique siteNode in the site repository. These siteNodes are constructed in the structure-tool in InfoGlue CMS. When the siteNode is located the ViewPage.action first checks which language it should render the page in. The URL also contain this information in the parameter languageId=1 which uniquely identifies for example English.
The next step is to find the template for this page. In the structure tool you define which template the page should use by binding a template-content to the template binding. As also templates are multi-language-enabled as all contents you should make sure that you fill in the master-language first. Most of the time you don't need localized templates and then you should use the primary language version for all templates.
When the template is located a TemplateLogic object is created and initialised with the context specified by the url-parameters siteNodeId, languageId and contentId. So when you code your templates you must be aware that most of the functionality will use the context in generating a response. This makes templates very reusable if you write well thought code in them. There are some situations when you wish to reach information about the current context and if you look in the misc-section those methods are specified. Syntax all functionality are reached by stating the following in a template:
org.infoglue.deliver.controllers.kernel.impl.simple.BasicTemplateController@10bbfac.{method name} where org.infoglue.deliver.controllers.kernel.impl.simple.BasicTemplateController@10bbfac gives you a reference to the templateLogic object and where {method name} is one of the methods specified later in this document.
Contents Contents are naturally one of the most important building blocks for a site. It is there text, images, pdf:s, templates and other information is stored. As you hopefully know contents are only available to a siteNode after you have bound it in some way in the structure tool. The reason for the binding-process is that we think reuse of content on multiple pages is one of the corner stones in content management. Often the persons writing the texts and the ones deciding where to put it on the site should not be the same. The concept makes the separation between pure content and site building is very clean.
As the InfoGlue CMS gives you a couple of different possibilities in how you bind contents this is also reflected in multiple ways of getting them in the templates. Below are some basic methods concerning ordinary text-contents. See the javadoc for a complete list.
getContentAttribute(String contentBindningName, String attributeName) This method deliveres a String with the content-attribute asked for. As the siteNode can have multiple bindings as well as a content as a parameter this parameter requires a bindingName which refers to the AvailableServiceBinding.name-attribute.
getContentAttribute(String attributeName) This method deliveres a String with the content-attribute asked for if it exists in the content defined in the url-parameter contentId.
getContentAttribute(Integer contentId, String attributeName) This method deliveres a String with the content-attribute asked for on the content specified.
getBoundContent(String structureBindningName) The method returns a single ContentVO-objects that is the bound content of named binding. It's used for getting one content.
getBoundContents(String structureBindningName) The method returns a list of ContentVO-objects that is the bound content of named binding. The method is great for collection-pages on any site. getBoundFolderContents(String structureBindningName, boolean searchRecursive, String sortAttribute, String sortOrder) The method returns a list of ContentVO-objects that is children to the bound content of named binding. The method is great for collection-pages on any site where you want to bind to a folder containing all contents to list. You can also state if the method should recurse into subfolders and how the contents should be sorted. The recursion only deals with three levels at the moment for performance-reasons. |
Digital Assets Contents can be of two different kinds at the moment. The previous section dealt with text-based content like a news item, an article or a simple label on the site. Most sites however also has need for binary contents like images and binary documents (PDF, Word, Excel etc.) among others. The InfoGlue platform handles the last category as Digital Assets and there are a number of ways to handle them as well. The assets themselves are stored in the database with all other content but are at request written (and cached) to file and reachable through a URL.
getAssetUrl(String contentBindningName) This method deliveres a String with the URL to the digital asset asked for. As the siteNode can have multiple bindings as well as a content as a parameter this parameter requires a bindingName which refers to the AvailableServiceBinding.name-attribute. getAssetUrl(Integer contentId) This method deliveres a String with the URL to the digital asset asked for. getAssetUrl(Integer contentId, String assetKey) This method deliveres a String with the URL to the digital asset asked for. getAssetUrl(String contentBindningName, int index) This method deliveres a String with the URL to the digital asset asked for. As the siteNode can have multiple bindings as well as a content as a parameter this parameter requires a bindingName which refers to the AvailableServiceBinding.name-attribute. getAssetUrl(String contentBindningName, String assetKey) This method deliveres a String with the URL to the digital asset asked for. As the siteNode can have multiple bindings as well as a content as a parameter this parameter requires a bindingName which refers to the AvailableServiceBinding.name-attribute. getArchiveBaseUrl(String contentBindningName, String assetKey) This method deliveres a String with the URL to the base path of the directory resulting from an unpacking of a uploaded zip-digitalAsset.
getArchiveBaseUrl(Integer contentId, String assetKey) This method deliveres a String with the URL to the base path of the directory resulting from an unpacking of a uploaded zip-digitalAsset. getArchiveBaseUrl(String contentBindningName, int index, String assetKey) This method deliveres a String with the URL to the base path of the directory resulting from an unpacking of a uploaded zip-digitalAsset.
getContentAttributeAsImageUrl(String contentBindningName, String attributeName, int canvasWidth, int canvasHeight, int textStartPosX, int textStartPosY, int textWidth, int textHeight) This method deliveres a String with the content-attribute asked for generated as a gif-file. That is - the text is printed as an image. getContentAttributeAsImageUrl(String contentBindningName, String attributeName, int canvasWidth, int canvasHeight)
This method deliveres a String with the content-attribute asked for generated as a gif-file. That is - the text is printed as an image. |
|
Structure / Navigation As contents, structural elements are naturally one of the most important building blocks for a site. It is there navigation, site-structure and other things are decided. As with contents relations between pages/siteNodes are defined through bindings in the structure tool. As the InfoGlue CMS gives you a couple of different possibilities in how you relate siteNodes to each other and this is also reflected in multiple ways of getting them in the templates. Below are some basic methods. See the javadoc for a complete list.
getPageUrl(String structureBindningName) This method deliveres a String with the URL to the page asked for. As the siteNode can have multiple bindings the method requires a bindingName which refers to the AvailableServiceBinding.name-attribute.
getPageUrl(WebPage webpage, Integer contentId) This method just gets a new URL but with the given contentId in it. getPageBaseUrl(String structureBindningName) This method deliveres a String with the URL to the page asked for. As the siteNode can have multiple bindings the method requires a bindingName which refers to the AvailableServiceBinding.name-attribute. getSiteNodeId(String structureBindningName) Getter for the siteNodeId on a specific bound page getPageUrl(String structureBindningName, Integer contentId) This method deliveres a String with the URL to the page asked for. As the siteNode can have multiple bindings the method requires a bindingName which refers to the AvailableServiceBinding.name-attribute. This method also allows the user to specify that the content is important. This method is mostly used for master/detail-pages. getPageUrl(String structureBindningName, int position, Integer contentId) This method deliveres a String with the URL to the page asked for. As the siteNode can have multiple bindings the method requires a bindingName and also allows the user to specify a special siteNode in an ordered collection which refers to the AvailableServiceBinding.name-attribute. This method also allows the user to specify that the content is important. This method is mostly used for master/detail-pages.
getCurrentPageUrl() This method deliveres a new url pointing to the same address as now but in the language corresponding to the code sent in. getPageUrlAfterLanguageChange(java.lang.String languageCode) This method deliveres a new url pointing to the same address as now but in the language corresponding to the code sent in. getPageTitle() The navigation-title is fetched from the meta-info-content bound to the site node. getPageNavTitle(String structureBindningName) This method deliveres a String with the Navigation title the page asked for has. As the siteNode can have multiple bindings the method requires a bindingName which refers to the AvailableServiceBinding.name-attribute. The navigation-title is fetched from the meta-info-content bound to the site node. getChildPages() The method returns a list of WebPage-objects that is the children of the current siteNode. The method is great for navigation-purposes on a structured site. getBoundPages(String structureBindningName)
getBoundPages(Integer siteNodeId, String structureBindningName) This methods get a list of bound pages with the structureBindningName sent in which resides on the siteNodeId sent in.
getLocalizedBoundPages(String structureBindningName) The method returns a list of WebPage-objects that is the bound sitenodes of named binding. The method is great for navigation-purposes on any site. We also filter out all pages that don't have a localized version of the page meta-content.
getBoundPage(String structureBindningName, int position) The method returns a list of WebPage-objects that is the bound sitenodes of named binding. The method is great for navigation-purposes on any site. getIsParentToCurrent(Integer siteNodeId) This method helps us find out if the current site node is the same or a child to the sent in one. So if the current page is a child(in the entire hierarchy below) below the siteNode sent in the method returns true. Useful for navigational purposes. |
Template reuse When you build a website or other visual representation of information there are often many reusable parts on a page. For example, you might want to reuse a header part for a lot of otherwise different templates. This is very much supported by InfoGlue. What you want to do is to identify the reusable parts and put them in their own template-content. They will have the same context as the calling template when processed which means that template can do anything the main template can. You can of course also include other templates in an included template so you get very small reusable components if that is what you choose.
include(String contentBindningName, String attributeName) This method allows the current template to include another template which is also rendered in the current context as if it were a part. |
Application Integration Many websites are nowadays full of functionality. This section will discuss some ways of integrating applications in a website without having to rewrite the application or perhaps just integrate an external applications logic into the site but still manage the look and feel yourself. We will also discuss how to build applications directly in the platform in a reusable and without making future upgrades difficult.
getUrlContent(String url) This method fetches a given URL contents. This means that we can include a external url's contents in our application. More to come.... |
Misc Here are some more functionality that is somewhat useful. Be sure to check out the javadoc for the complete list.
getSiteNodeId() Getter for the siteNodeId getLanguageId() Getter for the languageId getContentId() Getter for the contentId getRequestParameter(String parameterName) Getter for request-parameters getContentTypeDefinitionVO(Integer contentId) The method returns the ContentTypeVO-objects of the given contentId. |
Examples Below are some examples where we use some of the techniques stated in previous chapters. This is to give you an understanding of how it actually looks like in real life. We think that Apache Velocity makes scripting very easy and separation very clean. There is no way to clutter the template with ugly java code. Any HTML-coder should get started pretty quickly if all content and bindings were set up first. Often we recommend that the HTML is first developed and that the hard-coded texts are then replaced by calls to the cms but this is a matter of taste. You will soon find the most efficient way to work in your organization or in your project. The first example is fairly simple just to make a point. The resulting web page will look like this:

The above web page (although not very nice) exemplifies some basic functionality of InfoGlue. To produce the page a template would look like the code-section below. To make it a good example I've kept all layouts as simple as possible and focused on how to integrate InfoGlue-based content in the page. The example of course presumes that all contents, sitenodes and bindings have been set up correctly. Please see the CMS-tutorial for example on how this is done.
|
<head> <title>$templateLogic.pageTitle</title> </head>
<body bgcolor="white">
<table border="0" cellpadding="2" cellspacing="2" width="600"> <tr> <td colspan="2"><img src="$templateLogic.getAssetUrl("Global images", "Logotype")"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td valign="top" width="100"> <b>$templateLogic.getContentAttribute("Global labels", "MenuHeader")</b> <p> #foreach($boundPage in $templateLogic.getBoundPages("Left navigation")) <a href="$boundPage.url" class="nav">$boundPage.navigationTitle</a><br> #end </p> </td> <td> <img src="$templateLogic.getContentAttributeAsImageUrl("Main article", "Title", 449, 76)" width="449" height="76"/><br> $templateLogic.getContentAttribute("Main article", "Fulltext") </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2" align="center"> $templateLogic.getContentAttribute("Global labels", "CompanyPhoneNumber") | $templateLogic.getContentAttribute("Global labels", "CompanyEmail") </td> </tr> </table>
</body> </html>
|
|