Understanding Content Injection

About this article

I consider this as a conceptual article and the objective is that any person regardless of his technical or functional role understands the concept of content injection and the advantages/disadvantages of it.
On purpose, this article doesn't go in depth to the technical approach for implement content injection, as can be different depending on the version of SDL Tridion used

What is content injection

Content injection is a methodology or a technique that allows you to build flexible and complex scenarios combining basic scenarios.
Is used in the context of dynamic publishing model, although could apply also to Static.

  • Reduces considerably the complexity in the schema design as you construct the relation between content items in RTF fields or programmatically

  • Covers scenarios that following the traditional schema design would be difficult to handle

  • Allows constructing scenarios where a piece of content can be reused in multiple places nested in different component presentations.
    Example: A banner that shows an image and a link can be used as a regular component presentation that the user adds into the page, but also could be displayed within an article.

  • The basis of the content injection is to nest component presentations within component presentations based on certain rules.

Concept

For nesting a component presentation within a component presentation the result of the render of the component presentation  must contain a reference to the component presentation/s that will be nested in.
The Output of the component presentation where you want to nest component presentations will contain a syntax that will be resolved during the publishing (Static Scenarios), during the retrieval of the page in delivery system (Dynamic Scenarios) or during the preview of the page (Static, Dynamic)
This syntax will include the information related to publication id, component id and component template id.   Example:  Using for instance the Bra-ket notation all the information needed for inject a component presentation in another component presentation can be represented as <PUBID|CID|CTID> where
PUBID is the publication id

  • CID is the component id

  • CTID is the component template id

In a real implementation you can choose to use a tag libraries, a user control, etc...

For use content injection with dynamic publishing you need to work the following areas:

  • CMS area

  • Delivery area

 For use content injection with static publishing you need to work in the following area: 

  • CMS area

From Your Templates

In this scenario you can add directly the syntax without having to translate the component link notation, as no user intervention is required.
In order to choose the combination of component/component Template you can think in setup an embeddable schema that contains a component link field plus a dropdown where the user chooses the template. (This has some limitations as you will need to control to display the templates associated to the proper schema, etc...) or you could set the component template that will be used in configuration
Again, in 2011 you can think in an extension that helps you doing this.
Example: If you want to construct a list of Articles component showing the article intro, you can create a schema that groups those and link to components based on the schema article
Let's assume that the component template will display a list of introduction to those articles.
Again, there are 2 different possibilities

Dynamic Scenarios
The component template will display the syntax that will be interpreted in the delivery server, as for instance

div>
                                 <div> Here the List of Articles </div>             
                                  <pid1|cid1|ctid1>
                                  <pid2|cid2|ctid2> 
                                  <pid3|cid3|ctid3>     
                        </div>
 

<pid1|cid1|ctid1>  will display the following information extracted from the broker during the request of the page                             

   <div>  
                                  <div> Here the title of the Article 1 </div>              
                                  <div> Here the introduction to the Article 1 </div>
                         </div>

Static Scenarios
In this case all the html will be constructed at the time the component presentation is published  
                        <div>
                                 <div> Here the List of Articles Title </div>              
                                     <div> 
                                        <div> Here the title of the Article 1
</div>              
                                        <div> Here the introduction to the Article 1 </div>
                                    </div>
 
                                    <div> 
                                        <div> Here the title of the Article 2
</div>              
                                        <div> Here the introduction to the Article 2 </div>
                                    </div>
  
                                    <div> 
                                        <div> Here the title of the Article 3
</div>              
                                        <div> Here the introduction to the Article 3 </div>
                                    </div>
      
                         </div>

CMS Area

There are 2 different ways to use content injection in the CMS
The current UI allows you:

  • Create Component Links from RTF

  • Define Component Link fields in the schemas.

From RTF

You can use the concept of Component Link from an RTF area to nest component presentations into an RTF field.
This gives a lot of flexibility to the end user as he can construct pretty much any scenario within an RTF
The most important thing is to provide the user with a mechanism that allows him to give the instructions for nest component presentations
In order to identify  those "special" component links and standard component link, you have to take care of the following things:

  • Set information of the Component Template in the link

  • Indicate that this Component link will be resolved as a nested Component Presentation instead as a regular link.  For this you can use for example an specific target named "componentPresentationLink"

The following image illustrates a possible way to do that

With the new interface in 2011 probably the best approach is to create an extension that  allows you to choose the component and the component template

Depending on your implementation is not mandatory that the user chooses always the template. (For instance you could have the rule that if the user creates a component link to a component based on a certain schema, you add always a specific component template )

Add at the end of the Component Template a Template Building Block that resolve those "special" component links into:

Dynamic Scenarios:

The proper syntax that will be used in the front end for nest the component presentations. The output of those could be a Tag Library or a .Net control
Example: The syntax <a target="CT_BANNER" title="Banner Laplace Foundation" href="tcm:3-85">Here the banner promoting Laplace Foundation</a> will be translated into < 3|85|57> where 3 is the publication id, 85 is the component id and 57 is the component template id


Static Scenarios or Preview:

The logic for retrieve the content of the component Presentations nested in a component presentation
In this case you can parse the RTF text and make use of the RenderComponentPresentation method for those "special" component links,  as all will be resolved during rendering or preview and there is no need of write syntax that will be resolved in the front end. The result of that will be the final content/layout that will appear in the final component presentation

Delivery Area

The behavior here is relatively simple. You have to create a mechanism that resolves each component presentation added to the page and perform a recursive nest of the component presentations identified within the content of each component presentation.


Concept:
You need to implement the proper mechanism for parsing the content of each component presentation and replacing the tags that indicate the nesting with the content of the component presentation (retrieved from the broker) pointed from those .
There are several techniques for do that, you can use a scriptlet, tag libraries, user controls or you can take the advantages of using the rel functionality available for 2011.

Dynamic link Resolution
Because performance reasons, is better to perform the link resolution after the nest content operation is completed, so you will do that for each component presentation added into the page

Content Assembly flow in delivery

This section shows how is the process of nest the content of component presentations inside a component presentation in the delivery.
Let's discuss one real scenario. A page has the following structure, there are 3 Component presentations added to the page that contain references to other component presentations.
The following diagram shows how the page and component presentations are structured.

Each component presentation references other component presentations. Those references are set in the content of the dynamic component presentation that is published into the broker. Once one component presentation is retrieved we need to resolve those references and replace those with the content of the dcp referenced

 The following diagram shows 2 dcps with the references already resolved

The following diagram shows the final dcp that was added to the page with all the references to other dcps resolved

At this point the component presentation is ready for apply the dynamic linking and Site Edit if applicable and display in the page to the final user.

Example of Usage

Achieve Scenarios that change on daily basis without redesign the schemas is extremely difficult following a traditional model.

Content injection brings the flexibility for position component presentation content within another component presentation.

The following images show two versions of the same article showing different content as list of links, banner, promo in different positions, the editor only works in the RTF area and inject that content there,

no changes in templates are required in case that the article needs to be modified.

Article Version1

Article Version2

Pros and Cons of using Content Injection

Although sounds like a very powerful methodology, you need to do a depth analysis before you decide to use content injection or not.

In some scenarios fits perfectly and in some other is not recommended to use

Pros

  • Considerably reduction in the number of schemas needed for construct a website
  • Easy to achieve complex content agroupation scenarios without schema redesign
  • Gives a lot of freedom to the user when creating scenarios
  • Hability to react quickly to introduce changes in the site without changing schemas nor code 
  • You can have several levels of nesting, although is recommended to put a limitation because performance reasons 

Cons

  • Is a relatively abstract model for the users and can have some difficulties to understand how to create and maintain content  
  • You are adding a reference to the template in the content of the component, that can end up in some issues if you don't manage things properly, although there are techniques to minimize the impact. Also this practice can bring problems depending on the Blueprint Structure used
  • In case you use personalization, the out of the box personalization only will be applicable to the component presentations added into the page