3

I need to pass component field value like Component.Fields.Header to the C# TBB to do any manipulation.

I have created a C# TBB with parameter schema. parameter schema has a field Headertext of text type. In c# TBB , I have written below code to access parameter field value.

string headerText = package.GetValue("Headertext");

If I pass Component.Fields.Header as a parameter to the C# TBB using template builder. It considering this as a string instead of picking value of Component.Fields.Header.

8

If I understand well, the string headerText contains the component field you wish to retrieve in your c# TBB.

In that case, the package.GetValue("HeaderText"), will give you the actual value you enter in the HeaderText parameter schema field, so in your case, the string headerText will contain the string "Component.Fields.Header".

This means you are almost there, you should now just get the actual value from your component. YOu can do this very easily with this function (as explained in sdl tridion documentation http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-1140E189-6FDE-4221-914C-CB0D4BE29D74)

//first, get the param schema value
string headerText = package.GetValue("Headertext");

//then, get the component field as you defined from your parameter schema
string componentValue = package.GetValue(headerText);

Note that you will have to check for null values, in case you specify a non-existing field in your parameter schema field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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