Skip to main content

Posts

Showing posts from January, 2013

Resolve Static Links TBB

This week's TBB is about resolving Component links statically - i.e. at publish time. This is considered terribly bad practice , but sometimes, in the field, it is just what the custmer needs. It really goes against every Tridion principle and it will make the website completely inconsistent (e.g. dead links cannot be prevented). However, if you need to do it, this it how. The code below reads the 'Where Used' Pages for a Component. It takes the Page publish location URL and constructs a 'static' link to the Page. It will not even check if the page is published. public string ResolveLinkStatic( Engine engine, Package package, Component component) {     if (component.BinaryContent == null ) { // is Content Component         XmlElement node = component.GetListUsingItems(             new UsingItemsFilter (engine.GetSession()) {                 ItemTypes = new ItemType [] { ItemType .Page },                 IncludedVersions = VersionCondition .On

Resolve JS Images In Output TBB

The TBB of this week is Resolve JS Images In Output , originally written by my colleague Eric Huiza . Basically, the TBB does what the name says. It looks for certain images in the Output item and publishes them. The images have to be in TcmUri or WebDAV format and they must appear in the url('path') format. This is the format that a CSS background selector uses, for example, only that it appears in JavaScript. The TB transforms something like: document.getElementById(openingTitleId).style.background=     "url('/webdav/Content/Building Blocks/Assets/images/titlebar.gif') no-repeat"; into this: document.getElementById(openingTitleId).style.background=     "url('/assets/images/titlebar_tcm1-2.gif') no-repeat"; Description Name Resolve JS Images In Output TBB Type ·    T emplate in .NET Assembly Description Used to: ·     Resolve references to Multimedia Components Tc

Resolve CSS Images in Output TBB

This week's TBB is Resolve CSS Images in Output TBB . This template identifies unresolved image references inside CSS selectors " background: url('tcm:x-yy') ", publishes the MMC and replaces the reference with the resolved URL. I got this TBB from my colleague Eric Huiza , so he gets the credit for it ;) Name Render Css Images In Output TBB Type ·     Template in .NET Assembly Description Used to: ·     Resolve references to Multimedia Components TcmUris inside CSS syntax; ·     Publish the MMC and replace the TcmUri reference with the resolved URL; Notes: This generic TBB uses the Output item to search for references to MMC TcmUris (or WebDav URLs) inside CSS ‘ background ’ selectors. If such MMC TcmUri is identified, the MMC is published (to the mapped Structure Group) and the returned URL replaces the TcmUri reference. The Output item is rewritten with the resolved URLs. Parameters n/

Event System to Create Mapped Structure Groups for Binary Publish

As a continuation of last week's Publish Binaries to Mapped Structure Group , this week's TBB is in fact the Event System part of that solution. Make sure you do check out the previous post first, which explains why and what this Event System does. To reiterate, the Event System intercepts a Multimedia Component save, take its Folder path and create a 1-to-1 mapping of Structure Groups. The original code was written, again, by my colleague Eric Huiza : [ TcmExtension ( "MyEvents" )] public class EventsManager  : TcmExtension {     private Configuration configuration;     private readonly Regex SAFE_DIRNAME_REGEX = new Regex ( @"[\W_]+" );     public EventsManager() {         ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap ();         fileMap.ExeConfigFilename = Path .GetDirectoryName( Assembly .GetExecutingAssembly().Location) + "\\EventSystem.config" ;         configuration = ConfigurationManager

Publish Binaries to Mapped Structure Groups

Today's TBB of the Week comes from the high demand in the field to publish binary assets to different mapped Structure Groups. By default SDL Tridion offers two ways of publishing binaries: All binaries publish to a folder defined in your Publication properties; All binaries rendered by a given template publish to a folder corresponding to a given Structure Group; In my view, both cases are terrible, over-simplified and not representing a real use-case. Nobody in the field wants all binaries in one folder and nobody separates binary locations by template. Instead, everybody wants a mapping mechanism that takes a binary and publishes it to a given folder, defined by a Structure Group, and this mapping is done using some kind of metadata. More often than not, the metadata is the TCM Folder location of the Multimedia Component. I have seen this implemented numerous times. So the solution to publish binaries to a given location implies finding a mapping from a TCM Folder to a