What can we loop in the blocks of template templates DWT (Layout)?

I understand that from ready-made boxes, you can cycle through or sort arrays into DWT Template Building Blocks (TBB) with the following.

<!-- TemplateBeginRepeat name="array_name" --> <!-- template logic --> <!-- TemplateEndRepeat --> 

The documentation describes the predefined elements of the package , as well as how to use them .

In conclusion, we can use:

  • Component to reference the current component when iterating over components or component presentations
  • ComponentTemplate to reference the current component template when iterating over component presentations (this will be at the page level)
  • Field to refer to the current field when iterating over fields, as well as fields with multiple values.
  • FieldPath to get the full path to the iterated element. This is useful when using TemplateRepeatIndex inside a nested loop, as shown in the Tridion Practice Book . *
  • TemplateRepeatIndex , zero-based loop counting.

We can execute nested loops on Fields in a given component in a loop of the Components array, as well as by conditionally checking a specific field name when iterating over multi-valued fields.

I saw double queries inserting DWT syntax (e.g. @@Image_${TemplateRepeatIndex}@@ as described in another Tridion blog ).

Question (s)

Of course, are these elements or arrays / collections in the composite Package template, to the right (either by default, or according to our code)?

Can we "iterate over" individual elements in a package?

For example, if we have separate components in the Package , we can "iterate over" them to something like @@Component${TemplateRepeatIndex}@@ ?

  • Component1
  • Component2
  • Componentent3

I see that I can refer to such an element in a loop, but everything I saw suggests the following is not possible:

 <!-- TemplateBeginRepeat name="@@Component${TemplateRepeatIndex}@@" --> <!-- do something with @@Component${TemplateRepeatIndex}@@ --> <!-- TemplateEndRepeat --> 
+7
source share
2 answers

Basically, the DWT template allows you to iterate through arrays, and there is only one type of array in the Package that we can click on ourselves, this is the Component Presentation array (which can contain the TCMURI components of the Component Template, but also the Component TCMURI).

With this, you can click (what I call) the Dummy Component array in the package, which you can use to cycle through, and then use the double search function to make it work like a loop over a set of package variables.

For example, you insert a Component Array package with three dummy TCMURIs (they can all be tcm: 0-0-0, no matter what value they have). Then you create three package variables: Var_0, Var_1, Var_2. Now in your DWT template you can use:

 <!-- TemplateBeginRepeat name="MyDummyArray" --> @@Var_${TemplateRepeatIndex}@@ <!-- TemplateEndRepeat --> 

Which will result in the values โ€‹โ€‹of the three package variables.

Unfortunately, there is no way to create a string array directly or an array of fields, if so, so for everything you want to iterate over, you will have to use an existing array of fields or create a "massive component array".

From which we can really conclude that your example is impossible, as it is written, but when you click a dummy array with them in the Package, you can iterate over it and have what you want.

+5
source

Unable to create layout array with tcm: 0-0-0. He says that the element does not exist. Is there any other way to pass a dummy array through a packet so that the array can be encoded in DWT.

0
source

All Articles