I have around 50 lines of code in multiple page templates.
I am not able move it to a component template as I need component and template ID from page and render some text from the components in foreach loop.
I can not use context variable as the component template is DCP.
I am planning to move all of these 50 lines to either Razor TBB function or to a C# TBB. I am still POCing as how will I do that but I am confident that it should be doable.
My questions are-
1. Is there a better way that I am not seeing?
2. If I go with TBB option which will give me better performance: Razor TBB or the C# TBB? We have razor implementation for the page tempalate.
Below is the code snippet I have in page template-
@if(Package.FAQTopicCountFromPage == "1"){
@foreach (var cp in GetComponentPresentationsByTemplate("FAQ Topic")) {
@cp.RenderComponentPresentation()
}
}
@if(Package.FAQTopicCountFromPage != "1" && Package.FAQTopicCountFromPage != "0"){
<div id="id" class="classes">
<div>
<h2 id="id" class="classes">
@RenderComponentPresentation(Package.componetID, Package.templateID)
</h2>
<a href="javascript:void(0);" class="class" style="display: inline;">
@RenderComponentPresentation(Package.componetID, Package.templateID)
</a>
<a href="javascript:void(0);" class="class" style="display: none;">
@RenderComponentPresentation(Package.componetID, Package.templateID)
</a>
</div>
<div class="">
<div id="tabContainerID">
<ul class="class">
@foreach (var cp in GetComponentPresentationsByTemplate("FAQ Topic")) {
@if(cp.Index==0){
<li><a href="#tabs-1">Topic 1 Title (This is a render component presentation))</a></li>}
@if(cp.Index!=0){
<li><a href="#tabs-2">Topic 2 Title (This is a render component presentation)</a></li>}
}
</ul>
</div>
<div class="mainContainer">
@foreach (var cp in GetComponentPresentationsByTemplate("FAQ Topic")) {
@if(cp.Index==0){
<div id="tabs-1" class="">
Question Answers ul/li goes here for tab-1 (This is a render component presentation)
</div>
}
@if(cp.Index!=0){
<div id="tabs-2" class="">
Question Answers ul/li goes here for tab-2 (This is a render component presentation)
</div>
}
}
</div>
</div>
</div>
}