by

Copy and Paste Components Across Publications in Tridion

So, there’s a thing in Tridion that you can’t do: Copy and Paste components across publications.

And it’s kind of annoying. Especially if, say, you accidentally created 50 components in the wrong publication. Now what do you do?

Well, what I do is come up with a bookmarklet, to make it like it never happened. I also definitely don’t log the incident on my timesheet.

Back to Bookmarklets

Dominic Cronin hosted a bookmarklet challenge a while back, and I felt honored to have an entry come in second place (let’s face it, Alexander Orlov works for SDL R & D, is Ukrainian, and sports a beard that can develop bookmarklets better than I can).

But, my second-place-winning entry wasn’t all that fantastic. It was Pub Up!, a simple bookmarklet that leaves you in the same folder, but in a higher publication. I had another entry that was much further down, called an Anguilla Mediator. Despite the unimpressive name, that was the real magic, because Anguilla Mediator was a thing that made it easier to access stuff in the Tridion UI.

A Neat Trick with Anguilla Mediator

So, the Anguilla Mediator, amongst other things, has a property called currentItem, which is whatever thing that you have open.

So, when someone who I totally know and was definitely not me put 50 things in the wrong publication, I got an idea:

What if I copy the content from the open item into localStorage, and paste that thing from localStorage into an empty component?

So, that’s what I did. I used my store.js tool with Anguilla Mediator:

var AnguillaMediator = function() {
    this._getAnguillaFrame = function() {
        if (navHappy.isNavigating) {
            return window.top.frames[1];

        } else {
            return window.top;
        }
    };
    this.aFrame = this._getAnguillaFrame();
    this._getItem = function() {
        return this.aFrame.$models.getItem('tcm:' + navHappy.getCurrentTCM());
    };
    this.currentItem = this._getItem();
    this.copyContent = function () {
        var content = this.currentItem.getContent(),
            title = this.currentItem.getTitle();
        store.set(0, 'clipboard-title', title)
        store.set(0,'clipboard-content', content);
    };
    this.pasteContent = function () {
        var content = localStorage.getItem('clipboard-content'),
            title = localStorage.getItem('clipboard-title');
        console.log(content, title);
        if (content !== null && title !== null) {
            this.currentItem.setContent(content);
            this.currentItem.setTitle(title);
            store.del(0,'clipboard-title');
            store.del(0,'clipboard-content');
        }

    };
    this._getInfo = function() {
        return this.currentItem.getInfo();
    };
    this.info = this._getInfo();
    this.tcmID = this.info.ID;
    this.isPublished = this.info.isPublished;
};

How to use it

First, drag the Copy Component bookmarklet over to your bookmarklets bar.

  1. Open up the component that you want to copy
  2. Click the bookmarklet just one time
  3. Open up an empty component, with a matching schema
  4. Click the bookmarklet a second time

The Caveats

  • Tested only in Chrome
  • Tested only in Tridion 2013
  • May not work if you have component links

I still have some work to do in order to get component linking to work. But, because of how the bookmarklet was implemented, it accesses an external file that I’m hosting. So, once I sort out how to resolve component linking, the bookmarklet will be automatically updated for you.

The Big Idea

Bookmarklets can be fun — and useful. If you wanted to see all of the ones I’ve worked on, there’s a JSFiddle for that.

The Copy and Paste bookmarklet uses the Anguilla Mediator, which is not all that fancy to begin with. Give it a shot, and let me know how it works for you.