[DOCU-584] class vs modelClass Created: 22/Sep/15  Updated: 24/Sep/15  Resolved: 24/Sep/15

Status: Closed
Project: Documentation
Component/s: documentation-examples
Affects Version/s: short term
Fix Version/s: None

Type: Support Request Priority: Neutral
Reporter: asanka perera Assignee: Antti Hietala
Resolution: Not an issue Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Template:
Date of First Response:

 Description   

I have seen both the class and modelClass attributes in configurations.
Could you explain:

Difference between class vs modelClass attributes?
When do we use the class attribute?
How do we accees it from ftl files?

Regards
Asanka



 Comments   
Comment by Antti Hietala [ 22/Sep/15 ]

Hi Asanka,

The class and modelClass are documented in Template definition.

class is the item's definition class. As the name suggests, it defines the item. For example, the definition class of a template provides the template's title, template script and render type. Magnolia can read such details from configuration using the Node2Bean mechanism and set them in the definition class.

Magnolia provides default definition classes for all template types (pages, areas and components) so typically you don't need to create your own definition class unless you want to do something special. For example, the travel demo provides its own PageTemplateDefinition class although a generic one exists. The custom class has methods to get and set JavaScript files to be rendered at the bottom of the page. (Javadoc).

The definition class is available to the template script via the def rendering context object.

modelClass is Java model that contains business logic for the template. In a model class you can perform calculations, get content from somewhere else, or connect to a remote service. For example, the latestCommments component in the Commenting module has its own model class LatestComments which retrieves a list of latest page comments.

You should create a model class for item-specific logic. When you find yourself doing processing in a template script that is not reusable for other items such as other components, put the logic into a model class instead.

The model class is available to the template script via the model rendering context object.

https://documentation.magnolia-cms.com/display/DOCS/Template+definition
https://documentation.magnolia-cms.com/display/DOCS/Model
https://documentation.magnolia-cms.com/display/DOCS/Rendering+context+objects

Generated at Mon Feb 12 01:10:29 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.