P.Muralikrishna
P.Muralikrishna

Reputation: 1289

How to access properties of a Tridion component like schema name based on which it is created in aspx page?

I am customizing the ribbon tool bar by adding a button to it in TRIDION 2011 SP1 version. When I click on the button it will open an aspx page.Inside that aspx page I need to access the name of the schema used to create that component before creating the component itself(I mean to say while creating the component itself).

Please provide me a way to solve this issue. Thanks in advance.

Upvotes: 3

Views: 530

Answers (2)

Bart Koopman
Bart Koopman

Reputation: 4835

If you have the component (as an object), you can get it's schema id as Peter indicated. If you only have the component id, you can load the component and through that get to the schema.

When you need to load any item, you have to be aware that it's not a synchronous call in the UI API, so you should use delegate methods for that. For example something like this:

Example.prototype._loadItemInformation = function Example$_loadItemInformation(itemId, reload) {
    var item = $models.getItem(itemId);
    if (item) {
        var self = this;
        function Example$_loadItemInformation$_onItemLoaded() {
            $evt.removeEventHandler(item, "load", Example$_loadItemInformation$_onItemLoaded);
            // proceed with the actions on the loaded item here
        };

        if (item.isLoaded(true) && !reload) {
            Example$_loadItemInformation$_onItemLoaded();
        }
        else {
            $evt.addEventHandler(item, "load", Example$_loadItemInformation$_onItemLoaded);
            //$evt.addEventHandler(item, "loadfailed", Example$_loadItemInformation$_onItemLoadFailed);
            item.load(reload, $const.OpenMode.VIEW);
        }
    }
};

Also be aware the item could fail loading, you should actually also register an event handler for loadfailed (as my example code neglects to do).

Upvotes: 2

Peter Kjaer
Peter Kjaer

Reputation: 4316

You should pass it to your popup. The URI of the Schema is available on the Component model object within the CME - so your button command can access it and pass it to the popup (in the URL, for example).

var schemaId = $display.getView().getItem().getSchemaId();

Upvotes: 4

Related Questions