I am using SDL Tridion 2011 SP1. I am creating the Dreamweaver TBB for a component. In my component some of the fields are empty. But in my component TBB, I want to check if the field is empty and I should not render it. If field is not empty then I should render and display the value.I am facing the problem when checking the content of subfield in embedded field.
On my component there is one multi-value embedded schema field with name "EMBFIELD". The EMBFIELD schema has a text field with the name "text". I want to check if the text field is empty or not. If it is not empty I have to iterate over the field to render the values.
I have to render the field by "RenderComponentField" only. When I tried rendering it is showing some error that the field doesn't exist.
I thought that this can be done using If block.
<!-- TemplateBeginIf cond="Component.Fields.EMBFIELD" -->
<!-- TemplateBeginRepeat name="Component.Fields.EMBFIELD" -->
<!-- TemplateBeginIf cond="Component.Fields.EMBFIELD.text" -->
<div>@@RenderComponentField("Component.Fields.EMBFIELD.text",TemplateRepeatIndex)@@</div>
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->
But it's giving error like
Internal error: Context component Component does not have field Component.Fields.conditionalText.text
You could use StringLength(object parameter)
function, it will return 0 if the field is empty or if the string length of the parameter could not be determined. So all in all it should look like this:
<!-- TemplateBeginIf cond="StringLength(Component.Fields.Field) > 0" -->
<b>Value is not empty<b>
<p>@@Component.Fields.Field@@</p>
<!-- TemplateEndIf -->
This might be the answer to your updated question:
<!-- TemplateBeginIf cond="Component.Fields.EMBFIELD.text" -->
<!-- TemplateBeginRepeat name="Component.Fields.EMBFIELD" -->
@@RenderComponentField("EMBFIELD[${TemplateRepeatIndex}].text", 0)@@
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->