Publish To Twitter

This building block enables you to publish fields from a component to Twitter when a page is published without incurring additional work for the end user.

Description

By adding the TBB to a component template and filling in the fields in the associated parameter schema you can specify fields from the associated component to publish to Twitter. 

You can set whether the Twitter publication occurs once, on every publish, when the component is created or the specified fields are changed, or only when the specified fields in the component change. 

Additionally you can set the TBB to create a link back to the published page. 

Creating the parameter schema

First you need to create the parameter schema within your publication. You can either do this by using the schema file in the solution (in the resources folder) or manually entering the schema as below.

Using the schema file

If you are going to use the file from the solution, create a new parameter schema. Go to the source tab and replace everything from [xsd:annotation] to [/xsd:element] with everything from [xsd:annotation] to [/xsd:element] in the schema file (TwitterParameters.xsd), then save the schema, note the schema URI and proceed to creating the assembly.

Manual procedure

If you have created the parameter schema using the file, ignore this section. Create a new parameter schema. Add the following fields to the schema:

  • StringFormat (text field, required);
  • PublishMode (text field, required);
  • PublicationTarget (text field);
  • LinkToPage (text field, required);
  • PublicationRootURL (text field);
  • TwitterUserName (text field, required);
  • TwitterPassword (text field, required);    

Go back to the publish mode field and tick Values will be selected from a list. Add the following values:

  • Once 
  • Always 
  • When Created or Changed 
  • When Changed     

Set the field to be a drop down list and set whatever default value you would like.

Go back to the LinkToPage field, tick Values will be selected from a list and add the following values:

  • No
  • Yes   

Set the field to be a drop down list and set whatever default value you would like.

Save the schema and note the URI.

Creating the assembly

Open the solution and find the following line in the PublishToTwitter.vb file (on line 14, just above the class declaration)

[TcmTemplateParameterSchema("tcm:12-39658-8") _ ]

Replace the URI (tcm:12-39658-8) with the URI of the parameter schema you noted in the previous step.

Add references to the following Tridion-supplied dlls: 

  • Tridion.Common.dll 
  • Tridion.ContentManager.dll 
  • Tridion.ContentManager.Publishing.dll 
  • Tridion.ContentManager.Templating.dll    

Build the solution and upload the assembly to your publication using the TcmUploadAssembly.exe utility as normal. 

Usage

Add the Template Building Block (PublishToTwitter) to your compound component template. 

Click on the PublishToTwitter TBB and fill in the parameters as follows:

StringFormat 
Specify what you want to appear in Twitter. Use {} to denote a field from the component. 
Eg: Price drop {Title} is now {price}! 
(where {Title} and {price} are fields from the component) 
or: Media release {Title} 
(where {Title} is a field from the component) 

PublishMode 
Choose how frequently the Twitter feed should be updated by the publishing of the associated component. 

Once Only publish to Twitter once (as there is no way to find out definitely whether the component has previously been published, this is as close as can be achieved - it looks through the components used on each version of the page and checks whether a page has been published since the component was put on it) 

Always Publish to Twitter on every publish of the component 

When Created or Changed Publish to Twitter as per Once and also when the fields used in StringFormat have changed since last publish 

When Changed - Publish to Twitter when the fields used in StringFormat have changed since last publish 

PublicationTarget 
If you wish to restrict the template to only update your Twitter status when publishing to a specific publication target, specify the URI of the publication target here. If you do not specify a publication target URI your Twitter status will be updated when published to any target (according to the PublishMode) 

LinkToPage 
Choose whether you want to add a link to your Twitter status (Tweet). This uses is.gd to shorten the URL of the publishing page and suffixes the link at the end of your status. If the length of your status with the link added is longer than the maximum Twitter supports, your status will be shortened to fit and will be added before the url is suffixed. 

PublicationRootURL 
If you have chosen to include a link to your page you need to specify the URL root to your website (eg http://www.atl.org.uk). This allows an absolute link to be created to the page from Twitter. 

TwitterUserName 
Enter your Twitter account username (if you do not have an account, set one up at http://twitter.com

TwitterPassword 
Enter your Twitter password 

Save and close the component template. 

When you next publish a page containing a component using this component template it will update Twitter according to your chosen publish mode. 

Your updates will then be available to anyone who follows you.


Developer
Company
:    ATL
License agreement
Download package
Tags
:    Web2.0,  Social Networking,  Visual Basic
Version
:   1.0
Source
:   Yes

About the Author
Andrew Blackman
Developer

Solely responsible for development of the Associations websites and related technologies.

Association of Teachers and Lecturers

Most Popular Building Blocks

These are the most popular Building Blocks. Did you already get them?