How do I access the properties of a Tridion component such as the schema name it is based on in the aspx page?
I am customizing the ribbon toolbar by adding a button to it in TRIDION 2011 SP1. When I click on the button, it will open the aspx page. Inside this aspx page, I need to access the name of the schema used to create this component before creating the component itself (I mean, creating the component itself).
Please provide me with a way to resolve this issue. Thank you in advance.
source to share
If you have a component (as an object) you can get its schema id as Peter pointed out. If you only have a component ID, you can load the component and navigate through it to the schematic.
When you need to load any element, you need to know that this is not a synchronous call in the API of the interface, so you should use delegation methods for this. 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 that the element may not load, you must also register an event handler for loadfailed (as my example code does).
source to share