3

Iam working on tridion templating and i have 2 components associated with the same component template.I want to display one at the top and one at the bottom.How should I do that? If i use the below code on the top of the page and the bottom of the page the same component is displayed 2 times on the top and 2 times at the bottom. Kindly let me know how to display this component only once at the top and once at the bottom?

<!-- TemplateBeginRepeat name="Components" -->
              <!-- TemplateBeginIf cond="ComponentTemplate == 'Scripts'" -->

                                <!-- start the code-->
                                @@RenderComponentPresentation()@@
                                <!-- end the code--> 

              <!-- TemplateEndIf -->
 <!-- TemplateEndRepeat -->  

3 Answers 3

3

If you want to do it in DWT, You can use TemplateRepeatIndex variable for that, It is actually a 0 based Index. So inside the loop 0 would be your first component and 1 would the second one.

Try something like below:

    <!-- TemplateBeginRepeat name="Components" -->
                  <!-- TemplateBeginIf cond="ComponentTemplate == 'Scripts'" -->
    <!-- TemplateBeginIf cond="TemplateRepeatIndex == 0" -->
                                    <!-- start the code-->
                                    @@RenderComponentPresentation()@@
                                    <!-- end the code--> 
    <!-- TemplateEndIf -->
                  <!-- TemplateEndIf -->
     <!-- TemplateEndRepeat -->  

// Your Middle HTML goes here

    <!-- TemplateBeginRepeat name="Components" -->
                  <!-- TemplateBeginIf cond="ComponentTemplate == 'Scripts'" -->
    <!-- TemplateBeginIf cond="TemplateRepeatIndex == 1" -->
                                    <!-- start the code-->
                                    @@RenderComponentPresentation()@@
                                    <!-- end the code--> 
    <!-- TemplateEndIf -->
                  <!-- TemplateEndIf -->
     <!-- TemplateEndRepeat --> 
3

Currently your template is simply looping over all of the ComponentPresentations in the page (or more accurately, the list of ComponentPresentations call "Components". Typically you would develop a .Net based TBB which would first split or partition them into separate lists in the package according to your use case.

For more information and an example check out PartitionComponentPresentations · TridionPractice/tridion-practice Wiki · GitHub

2
  • cant we just display the components that are added in the page using simple DWT code? Adding the condition like <!-- TemplateBeginIf cond="TemplateRepeatIndex == 0" --> will help?
    – vids
    Commented Jan 10, 2017 at 10:06
  • Yes, you could, but are your components always going to be the same position everywhere your template is used? Commented Jan 10, 2017 at 10:12
3

Actually, there is easier way. We had similar issue and we did it by specifying exact tcmid of component and template in RenderComponentPresentation function as:

@@RenderComponentPresentation("${FooterID}","${PTStaticCCEmergencyFooterCTID}")@@

Basically, we extract footer id and footer template id via c# block, push them in package and then render explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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