Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to a Razor View rendering in Sitecore

I'm trying to render out the brightcove media player right now while passing a dynamic video id. The brightcoveData.Id is a valid guid but I can't seem to get the parameters passing properly so that the Rendering understands it. I get an error from this component saying "Media item are not selected."

var embedMedia = new System.Collections.Specialized.NameValueCollection();
            embedMedia.Add("playerId", "E7766078969C3AB892DD158E0E7230B9");
            embedMedia.Add("width", "400");
            embedMedia.Add("height", "300");

            @Html.Sitecore().Rendering("/sitecore/layout/Renderings/Media Framework/Embed Media", new
                               {
                                   DataSource = brightcoveData.Id,
                                   Parameters = embedMedia
                               })

Any help would be appreciated. Thanks.

like image 413
Thomas Taylor Avatar asked Dec 15 '14 21:12

Thomas Taylor


People also ask

Where does Sitecore store the rendering parameter?

Rendering parameter templates are managed in the same module as the code that uses them, either in the feature module where the rendering and controller logic resides or in a foundation level module.

How do I render a view in Sitecore?

To create a view rendering, right-click on the folder in your project where you wish to insert the . cshtml file and select Add > New Item…. Choose Sitecore in the left-hand menu, and select Sitecore View Rendering in the right-hand pane. Give the view rendering a name.

What is renderings in Sitecore and how we can create these?

You create renderings in the same way: Choose Sitecore View Rendering to create a View Rendering, and put the definition item in Renderings. Choose Sitecore Controller Rendering to create a Controller Rendering, and put the definition item in Renderings.


1 Answers

Ok, after talking to Sitecore Support I got an answer:

@Html.Sitecore().Rendering("/sitecore/layout/Renderings/Media Framework/Embed Media", new
                               {
                                   DataSource = brightcoveData.Id,
                                   Parameters = "playerid=E7766078969C3AB892DD158E0E7230B9&height=300&width=400"
                               })

brightcoveData.Id is just a guid string = "{XXXX-...-etc}". playerid is the Sitecore item id for the player you're using.

That's what the final code looks like and it works great! Thanks everyone

like image 87
Thomas Taylor Avatar answered Nov 08 '22 16:11

Thomas Taylor