Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the field in embedded schema is empty in Dreamweaver Template Building Block

Tags:

tridion

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

like image 225
Patan Avatar asked Feb 21 '23 04:02

Patan


2 Answers

You should be able to use the Dreamweaver conditional regions to check for a value before you attempt to render it.

For example:

<!-- TemplateBeginIf cond="Component.Fields.Field" -->
    @@Component.Fields.Field@@
<!-- TemplateEndIf -->
like image 193
Dave Houlker Avatar answered Apr 27 '23 12:04

Dave Houlker


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 -->
like image 28
Andrey Marchuk Avatar answered Apr 27 '23 13:04

Andrey Marchuk