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.

Thursday, May 15, 2014

SmartTarget talk on TDS

Today I shared about SDL SmartTarget and the Ambient Framework in a talk on the very first Tridion Developer Summit in Amsterdam. Here are the slides and some links I mentioned.


If you got hold of one of the 6 month Tridion licenses on the SDL USB sticks: have fun and let me know what you built with SmartTarget and ADF!

Many thanks to Robert Curlette for organizing the event.

Update June 9, 2014
Recordings of some of the talks are available on http://tridiondevelopersummit.com/videos/. Or straight to this talk http://vimeo.com/96997119.

Thursday, March 13, 2014

Creating a user with the SDL Tridion Core Service

I was at a new project this week creating a Tridion user for a developer in the team while discovering that the CME could not list the domain users. This can happen when the MTSuser does not have access to the domain. A simple Core Service tool helped out once again. This command line application creates a user, without lookup in the active directory. I needed only one user so I just ran it from Visual Studio. 

Other versions
This is for SDL Tridion 2013 SP1, for previous versions (Tridion 2011 and up) you might have to use another configuration name (basicHttp_2013 in this case) and replace the contents of the app.config with Tridion.ContentManager.CoreService.Client.dll.config. In the app.config you can update the url for the basicHttp_2013 endpoint to match the hostname of your Tridion Content Manager server. 

Code

PowerShell
Before using the Visual Studio solution I tried to create the user with the tridion-powershell-modules, I could not get that one to work due to some error but it is the best way to do this task: It supports all Tridion versions and no Visual Studio and bespoke command line applications needed.

Tuesday, January 28, 2014

Publish a page from PowerShell

Today I fiddled around with PowerShell and found you can pretty easily publish a page in SDL Tridion. This can come in handy for administrative tasks where you typically want to automate in scripting, to avoid to setting up a .NET console project with a lot of code to maintain.

The Tridion PowerShell Modules project comes in handy to get you a CoreService client. It's just five steps to install this module on your machine.
  1. Get the .psm1, .psd1 and DLL files from the project.
    You can also copy the CoreService DLL from the %TRIDION_HOME%bin\client\CoreService folder on your own Content Manager server if you do not like to download the DLLs from the project.
  2. Create a directory
    C:\Users\your_username\Documents\WindowsPowerShell\Modules\Tridion-CoreService
  3. Copy the .psm1, .psd1 and .dll files in that directory
  4. Restart any open PowerShell consoles or run Import-Module Tridion-CoreService in the open PowerShell console.
Once you can use the PowerShell module, run a simple script to publish the page.


Also see http://tridion.stackexchange.com/questions/4331/how-can-i-publish-a-page-by-using-powershell

As an example administrative task, take this question. For unclear reasons we need to publish a page every hour or so. This is not a Tridion best practice, but easy to automate. Just have a Windows Scheduled Task which runs powershell -file "C:\publish-a-page.ps1". That will do the trick effectively.

For future optimization: you could extend the Tridion PowerShell Modules to help you to perform this simple publishing action without setting up the PublishInstruction and ReadOptions and all.

Friday, January 3, 2014

Showing errors in a ECL mountpoint

External Content Library (ECL) Providers can raise error messages in a very user friendly way. The mountpoint can show a list item with the error message when it occurs and error and cannot get data from the external system. This avoids confusing the Tridion CME user with an error message in a popup and having an empty list.


This idea came up in a Tridion.Stackexhange Q&A on http://tridion.stackexchange.com/questions/3097/raising-an-error-from-a-ecl-provider

The solution is implemented in the Flickr ECL provider. See this commit to discover
how this works in more detail.

Basically the Flickr mountpoint will return a error message in a IContentLibraryListItem which represents the error. This ErrorListItem object will have it's own DisplayTypeId so that it can show error icons.

Tridion Core Service in PowerShell

The tridion-powershell-modules project is a PowerShell module written by Peter Kjaer which allows easy access to the Tridion Core Service through PowerShell. Windows PowerShell allows to use the CoreService client DLL and allows to create simple scripts to do Tridion CM maintainance.

This module introduces a number of Powershell commands like Get-TridionClient and Get-TridionUser to interact with the CoreService. Setup for Tridion 2011, 2013 or 2013 SP1 is super easy with the Set-TridionCoreServiceSettings command.

Find the module and the source code in http://code.google.com/p/tridion-powershell-modules/

Earlier I posted a Tridion.Stackexchange answer on how to install and configure the module in Windows Powershell http://tridion.stackexchange.com/a/3643/88

I use a little PowerShell script to remove and install the module when Peter releases a new version https://gist.github.com/jhorsman/7658365


tip #1

Make sure you put the module files in a directory named "Tridion-CoreService". A previous version required a directory names "CoreService" but the module is renamed. If the folder name and module name don't match you will get errors like "Import-Module : The specified module 'CoreService' was not loaded because no valid module file was found in any module".


tip #2

Run Get-Command -Module Tridion-CoreService to learn about the other command in the module.