How to check if a field is empty in an embedded schema in a Dreamweaver template template block

I am using SDL Tridion 2011 SP1. I am creating Dreamweaver TBB for a component. In my component, some fields are empty. But in my TBB component I want to check if a field is empty and I should not display it. If the field is not empty, I have to display and display the value. I am encountering a problem while checking the contents of a subfield in an inline field.

My component has a single multi-valued embedded circuit field named "EMBFIELD". The EMBFIELD schema has a text box called 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 display the values.

I need to display the field only with "RenderComponentField". When I tried to render, it shows some error that the field does not exist.

I thought this could be done using an 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 this gives an error, for example,

Internal error: context component The component does not have a Component.Fields.conditionalText.text field

+4
source share
3 answers

You can use the StringLength(object parameter) function, it will return 0 if the field is empty or if the length of the parameter string cannot be determined. So, everything 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 --> 
+2
source

You should be able to use conditional areas of Dreamweaver to check the value before trying to display it.

For instance:

 <!-- TemplateBeginIf cond="Component.Fields.Field" --> @@ Component.Fields.Field@ @ <!-- TemplateEndIf --> 
+6
source

We got the same error with the same error when accessing the built-in circuit field and after tons of back and forth with the builder and debugging dwt realized that the error is NOT to put a space between the last double qoute and → in the TemplateBeginIf statement .: Errors Using the DWT Broker:

 <!-- TemplateBeginIf cond="EMBEDFIELD.internalLink || EMBEDFIELD.externalLink || EMBEDFIELD.label"--> 

The following is the error:

 <!-- TemplateBeginIf cond="EMBEDFIELD.internalLink || EMBEDFIELD.externalLink || EMBEDFIELD.label"<PUT_A_SPACE_HERE>--> 

There may be any TemplateBeginIf surrounding the RenderComponentField statement with an error. Hope this helps someone.

0
source

Source: https://habr.com/ru/post/1401320/


All Articles