Wednesday, December 31, 2014

The year in numbers

A peek into the Broker database with the Content Delivery Web Service

The Content Delivery (CD) web service, aka OData service, can be used to inspect component presentations or other entities in the Content Delivery broker.

I sometimes see Tridion developers looking into the MS SQL or Oracle database if they want to check what is published. Most Tridion implementations use the CD web service and it is much easier and faster to look into this service. There are exceptions of course, if you want to inspect REL TCDL tags you still want to look into the database, the TCDL tags will get parsed by the Tridion stack when you retrieve content through the CD web service.

Here are a few simple steps to get started browsing though the OData endpoint of the CD web service.


1. Get the Content Delivery web service URL

You can find the URL of the CD web service in the Session Preview settings of the publication targets.


2. Browse the Content Delivery web service

Use Chrome. Firefox and IE try to parse the feed generated by the CD web service and do not show the Atom XML.

Browse to the URL, you will see this listing. Do not forget the tailing / in the URL or you will get the service’s WCF info page instead of the feed. In this example the base URL is http://stg2013sp1demo.ams.dev:84/odata.svc/


This page shows lists all entities available in the Content Delivery web service, ranging from BinaryVariants to Schemas.

3. Digg in into collections

Explore the collections of entities, for example the dynamic component presentations: http://stg2013sp1demo.ams.dev:84/odata.svc/ComponentPresentations


Each component presentation is vieved in a < entry > element. the element contains the full URL to this entry, for example http://stg2013sp1demo.ams.dev:84/odata.svc/ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)

4. Select an entity by id

Grab one specific entity, for example to check it is published correctly:
http://stg2013sp1demo.ams.dev:84/odata.svc/ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123) 
 
The Content Delivery web service is aware of typical CD entities like pages and component presentations, but also the underlying items like schemas and components.

5. Get related entities

The feed is self-explanatory, the nodes show the URLs to dig in deeper into the feed. In the previous example you see the link elements which link to related entities and entity collections.
  • Entity URL
    ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)
  • Component entity for this component presentation
    ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)/Component
  • Component template for this component presentaiton
    ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)/Template
  • Pages where this component presentation is used
    ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)/Pages

 

6. Expand

Entities can be expanded to show more information in one go, for example you can show the full component entity in the component presentation entity.

For example get a component presentation and the linked component:
http://localhost:84/odata.svc/ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)?$expand=Component


Note the < m:inline > element which contains the component entity.


7. Get a field

The OData protocol used for the CD web service also allows to select specific field or field value of an entity. For example the title of the component in the previous example.

http://localhost:84/odata.svc/Components(ItemId=111,PublicationId=6)/title/$value
or
http://localhost:84/odata.svc/ComponentPresentations(PublicationId=6,ComponentId=111,TemplateId=123)/Component/title/$value

 

Tuesday, December 30, 2014

SmartTarget tags: from template to page

I recently shared some SmartTarget Gists which show step by step how a SmartTarget region grows from a simple region tag in a Dreamweaver template layout TBB to the fully expanded SmartTarget controls or tags on an aspx or jsp page.

What follows is a number of code snippets from my Gist account. I shared some of this in a Tridion.Stackexchange answer.

Those code snippets all show one SmartTarget region which queries for SmartTarget promotions, the Experience Manager  markup and three fallback component presentations.

Step 1: Template

The Dreamweaver template TBB contains a region tag. 

source: https://gist.github.com/6053b09d0ccbd31e058b

The SmartTarget TBBs "Add SmartTarget Query", "Add Promotions" and "Apply SmartTarget Settings" (see manual) specify the region name and other settings and transform the region markup into TCDL tags. These are all default SmartTarget TBBs.

Step 2: TCDL

The TCDL tags form the instructions for the SmartTarget region in a platform neutral way. The Content Delivery deployer application transforms the TCDL tags into .NET Controls or JSP tags. For a REL target the deployer keeps the TCDL tags in the page content and DCP content and the TCDL tags are executed on runtime in the web application.

source: https://gist.github.com/3b5c48c3a5ea5d5e12b8

Step 3: controls and tags

The .NET controls, or JSP tags, or TCDL tags for a REL get the promotional content.
  1. The Query control/tag constructs a SmartTarget query
  2. The Promotions control/tag specifies what promotion region to query for, and how many results should be shown.
  3. The ComponentPresentation control/tag gets the component presentation. Note that this is not a SmartTarget control/tag and uses variables for ComponentURI and TemplateURI from the SmartTarget query result and uses the core Tridion CD functionality to get the component presentation.
  4. If the SmartTarget query does not return any promotions the contents of the FallbackContent tag are shown.
.NET source: https://gist.github.com/70d569023e78081c3b57

JSP source: https://gist.github.com/83e45c851b63481e39bb

Step 4: HTML with XPM markup

The web application renders the HTML which is parsed by the browser. This example includes the Experience Manager markup which would only be visible on a staging target. Note the Experience Manager markup is added to annotate the SmartTarget region.


source: https://gist.github.com/ea7312358ce22a61bbea

Tag demo

This tag demo in ASP.NET or JSP might come in handy to understand what each while troubleshooting SmartTarget promotions on your website.


Sunday, December 28, 2014

Random Weather: an sample ADF cartridge

What better way is there to explain ADF than by an easy to read example: the random Weather Cartridge. The SDL Tridion Ambient Data Framework (ADF) is used for SmartTarget, Experience Manager, and the context engine. Especially for SmartTarget it is common to create your own cartridge. A cartridge can put information about the web visitors context the ADF claim store which in turn can be used in SmartTarget triggers.

This example cartridge puts in a random temperature and weather type. A real cartridge would look up the weather at a third party service, much like the Quova Cartrdige does.

I have put the weather-cartridge project up on GitHub. You can read this to explore ADF, or use it as a basis for your next project. Have look at the readme in the project for more details and build instructions.

The Maven project contains the Jetty plugin and a test webapp to test the cartridge.

Eric Huiza described the ADF mechanism in more detail earlier.

Thursday, December 18, 2014

A handy documentation bookmarklet

The bookmarklet challenge on Tridion Stackexchange inspired me to try my JavaScript skills and write my first bookmarklet. This bookmarklet is very Tridion related, although not really enhancing the Tridion GUI

Is shared the compact bookmarklet on gist, and the whole thing on GitHub.
Almost daily I log in multiple times into the SDL documentation portal, aka LiveContent or "The Manual". Unfortunately the browser does not remember the password for this site. This bookmarklet for the challenge fixes this problem and the browser remembers the login.

This is how to use this:
  1. Make a new bookmark
  2. Paste this script in the Location field of the bookmark (full source).
  3. Once on the LiveContent website just click the bookmarklet and the browser will offer to remember your credentials.
 

How this works

The browser does not try to remember the credentials for this site because the login form is not a proper HTML login form with a form tag and submit button. The bookmarklet hides the original login button and adds a new login button image, a form submit button and wraps the form in a form element. Clicking the new login button (just a clickable image) will set a series of events in motion. The new login button click triggers a click on the form submit button, the form submit triggers the browser to ask you to remember the credentials, the form submit action is to click the original login which sets some LiveContent mechanism in working.

I did not bother to study how the LiveContent login actually works and I think the beauty of this solution is that it leaves the original login page intact, it only adds and hides nodes in the dom document.

Note

I could have made a bookmarklet which logs you in directly, without leveraging the browser form auto completion, that would be even faster to use, but I do not like the fact that the bookmarklet would store the credentials, even if the credentials are not that sensitive and secret.