3

I have the following requirement: On specific page type I need to render existing CP multiple times each time using (translated) component from different language publications. This way, I will have content in different languages on the same page.

My output needs to look something like this:

<h1>Page 1</h1>
<p>Hello....</p>
<p>Guten Tag...</p>
<p>Hola ....</p>

Approach I used is to get the component from each language publication, render it with CT and add output to the page. Sounds simple. First part is working fine, from CP I get the component, and then based on the id/webdav path of that component I get (translated) component from specific language publication. The second part, rendering not so easy...

When I call RenderComponentPresentation in publication A and provide component and CT from publication B Rendering is done with items from publication A.

Is there something else I can use to do the rendering?

2
  • 1
    Can you paste here, how are you using "RenderComponentPresentation" function in your TBB? Commented Aug 11, 2015 at 13:40
  • I am using engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id), so during execution in publication 10 I have something like engine.RenderComponentPresentation(55-123, 55-456-32)) (as I want to render item in publication 55) Commented Aug 11, 2015 at 15:13

2 Answers 2

2

One option is to create a new C# Template Building Block to handle the rendering of this content. This TBB would go before your design on the template and place an HTML string (or multiple HTML strings, depending on how you wish to organize things) onto the package. Then your design simply grabs the value from the package and adds it in the appropriate places to your page. It is fairly straightforward to get local versions of components using the TOM.Net API and access their fields. Using these, create a string with the HTML you want and use the following to place it onto the package.

package.PushItem([[value name that will go on the package]], package.CreateHtmlItem([[your HTML string]]));

After you have the value on the page, assuming you're using DWTs, you would use

<!-- TemplateBeginIf cond="[[value name that will go on the package]]" -->@@[[value name that will go on the package]]@@<!-- TemplateEndIf -->

to render the package values in your template.

3
  • this is not related to the problem I have. My problem is that I want to render items component and CT from publication A in publication B and RenderComponentPresentation called from publication B does not work that way. Commented Aug 11, 2015 at 13:29
  • 2
    My solution will help you to reach your end goal of writing out html based on different localized versions of components. It just comes at it from another angle rather than using RenderComponentPresentation, which is only one way to write out html. If you are not required to keep all of the rendering in the design then you can use a C# TBB which makes it easier to move between publications and handle different components. If you are committed to keeping the rendering in a design, then my solution won't help and someone else will likely present an alternative idea. Commented Aug 11, 2015 at 13:42
  • 1
    unfortunately this solution would require to re implement all templates as, although template output is html, the logic behind is a little more complex and it require more info then it is stored in the component that is rendered Commented Aug 11, 2015 at 13:52
2

After a lot of searching, I have managed to find the solution on Preview a Component Presentation from TBB code (which would make this a duplicate question)

Tnx everyone for your Help

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.