Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I have schema A that has the field called Keys which is embedded schema type. The embedded schema consists of 2 fields that is the keyname and keyvalue. I have created component using schema A. After that I created parameter schema and gave the componentpath in the field such that I can access the component path. That parameter schema assigned to the TBB.

Now I want to read the component path and want to read for the particular keyname this is the keyvalue using C# TBB.

share|improve this question

1 Answer 1

The text below is OK - but irrelevant to the actual question. To read the parameter of a TBB, simply use this:

string value = package.GetValue("FieldName");

Where "FieldName" is the (XML) name of the field of the parameter schema.

This is relatively simple to do...

You need to first load an instance of the EmbeddedSchemaField, then read it's child nodes. It's very easy to visualize if you look at the XML of the component:

<Content>
  <Field>Some value</Field>
  <EmbeddedField>
    <Key>Key</Key>
    <Value>Value</Value>
  </EmbeddedField>
</Content>

In c# you'd write something along these lines:

ItemFields content = new ItemFields(component.Content, Component.Schema);
ItemField embeddedField = (ItemFields)content["EmbeddedField"];;
TextField textField = embeddedField["Key"];
String textFieldValue = textField.Value;

Or even simpler if you happen to have the DGX installed.

EDIT

If you know the key name, and want to find the corresponding value, I'd probably use something like a KeyValuePair or a simple Dictionary(String,String), load the various key/value pairs into it the first time you try to load a value, then use simple String value = dictionary[key] in my code.

share|improve this answer
    
I see - you know the key, and want the corresponding value? Might be simpler to do with XML actually... –  Nuno Linhares Aug 25 at 8:22
    
@ Nuno linhares sorry the question which i have asked above is not clear. I have created parameter schema that has the field component path, this parameter schema assigned to the tbb. while creating a page only the component is attached with it's particluar ct but it will not come to know from which component rendering the key name and key value in that case assigned the parameterschema to the tbb. Now first i want to read the component path from the parameter schema, create object of it and latrer want to read the keyname and keyvalue in C# –  k951 Aug 25 at 8:26
    
Oh - getting the value from the Parameter schema? That's an easy one, it should be available in the package... let me check. –  Nuno Linhares Aug 25 at 8:33
2  
package.getValue('keyname')? –  Frank van Puffelen Aug 25 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.