I am doing inline call's to RenderComponentPresentation from a CT (CT carousel, which renders individual carousel items with CT Item). Challenge: items need to know their position within the carousel.

I am currently using Context Variable (engine.PublishingContext.RenderContext.ContextVariables.Add) to set the position variable before calling each RenderComponentPresentation.

Are there any risks in using this approach? Are Context Variables "shared" outside my current rendering context (for example during publishing of SG, or multiple pages, with multiple publishing threads...) ?


The scope of the context variables is a publishing transaction, so if you publish a page, then the scope is just the publication of that page, if you publish a structure group, the scope is the publication of all content within that structure group (it's also discussed in this blog post : http://www.tridiondeveloper.com/using-context-variables-as-a-templating-cache)

Now, if you are afraid that the variable may be overwritten, you could always uniquely identify your context variable. For example using something like

 engine.PublishingContext.RenderContext.ContextVariables.Add("{page_tcm_uri}_carouselposition", 1);

That way, the position is unique for a specific page.

There are of course other options: you could write a .NET TBB that loops over all component publications, gets all carrousel components, and renders them out. That way, you can keep a position counter within your .NET code, and you don't need to put it in context variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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