-
Notifications
You must be signed in to change notification settings - Fork 7
Context Processors
A Context Processor is a Java Class used to provide Content Model properties to the presentation layer scripts. These properties exist within a Context, e.g. content.text, or global.siteRoot, custom-context.custom-property, etc. The source of these properties can be the repository (an unprocessed property), or a processed version of the property, or a completely new property computed during the execution of the Context Processor.
This model of providing functionality leads to a design pattern: front-end components dynamic functionality is provided by an independent, reusable, and pluggable set of Context Processors.
Context Processors are pluggable and reusable. Instead of re inventing the wheel, you determine the common back-end functionality and then reuse it in all components that share the same functionality.
Context processors can be executed as independent units or in chain and each one expects certain input and generates an output that is stored in the content model.
Danta promotes the loose coupling between the logic and presentation layer. It is fundamental to avoid complex operations in the component script. This is achieved by the context processors, the context processors are the implementation of the logic defined by the business rules and add the result of those operations into the content model, by doing this the component script is only in charge of displaying content and defining the markup.
When a request is sent to the server the Context Processor is executed and is used to modify properties/values within the Content Model.
Context processors apply transient changes to the Danta content model and you can control the execution order of the context processor by setting the priority of each context processor. These transient changes can be reused through different context processors. This is what extension through composition instead of inheritance means. The combination between temporal changes to the content model and execution order control enables you to manipulate the values stored in the content model and reuse functionality already implemented without the need to extend a context processor.
For example you can add content to an existing property (e.g. the author writes the value "Blog created on") and the Context Processor will add the date the blog was created. Another example is creating a new property, for example a property “countBlogs” that will hold a text like e.g. “ The amount of blogs: ” and then a routine counts the blogs and adds the result to the property.
Another way to think about this concept is to image an assembly line. Products come unfinished (1) from a different department (e.g. the repository) but must be completed before they're shown in the presentation layer. Context Processors act as modular assemblers, they may add, remove or modified the contents of the unfinished product (2). More than one context processor may be executed for a given product (3). After appropiate Context Processors have been triggered for a specific product (the content model), the content model is ready for show (the presentation layer) (4). As you can see, Context Processors are a dynamic and powerful way to manipulate any property in a transient way (not storing to the repository) prior to using it in e.g. a component script.