5
votes

I have a page template in Tridion 2011 with Razor code that prints information based on RenderComponentPresentation() as the first thing in the page. No other markup comes before it, because the component, not the page, contains the initial markup. Unless I put at least one character before the first RenderComponentPresentation in the published output, the template refuses to render any presentations.

So, for example, if this is all that is in the layout TBB this works (in my real code the tcms are real of course):

<
@RenderComponentPresentation("tcm:mytcm","tcm:myothertcm")

but this does not

@RenderComponentPresentation("tcm:mytcm","tcm:myothertcm")

The first prints the contents of the component preceded by the "<", whereas the second does nothing at all. I don't want to have ANY markup directly at the start of the page template, I want the first thing to be the component. Is it possible?

3
I have never used the Razor mediator before, so this is a shot in the dark, but you could try this: @{ RenderComponentPresentation("tcm", "tcm") } - Albert Romkes

3 Answers

3
votes

I've just done a quick test in Template Builder using the latest version of the Razor Mediator (1.2) and couldn't replicate your issue.

Maybe you could try:

<text></text>
@RenderComponentPresentation("tcm:mytcm","tcm"myothertcm")

It won't render any additional markup but may trick the mediator into doing what you want (though like I said, I can't replicate your problem so can't verify whether it does).

2
votes

Normally with Razor you iterate over any and all Component Presentations on the page, and right now I'm working with

@foreach(var cp in ComponentPresentations){
   @cp.RenderComponentPresentation()
}

This will render every component on the page, regardless of predefined schema's or templates. Your issue however suggest a problem elsewhere. What kind of output does your page template generate (do mind its the page template using a compound template which in turn includes the Razor TBB you describe here). Is it .aspx, HTML or other? And what is the Component templates' output? is it an HTML fragment, or anything else?

As far as you syntax goes, that should be just fine other than the template invocation:

@RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx")

I have a feeling this code only works when used within HTML tags, though, but that's just a hunch.

1
votes

Bit of a hack but have you tried:

<text>@RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx")</text>

or

@Html.Raw(RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx"))

Disclaimer: not really used Razor mediator. Just Razor.