I want to display youtube or vimeo videos on a page.
I already created a specific schema and a component template so that the user can add the videos to a page via the component presentations of the page. This is working perfectly.
The dreamweaver component template looks like:
<!-- TemplateBeginIf cond="Provider == 'YouTube'" -->
<iframe id="ytplayer" type="text/html" width="@@Width@@" height="@@Height@@" src="http://www.youtube.com/embed/@@VideoID@@" frameborder="0"/>
<!-- TemplateEndIf -->
<!-- TemplateBeginIf cond="Provider == 'Vimeo'" -->
<iframe src="http://player.vimeo.com/video/@@VideoID@@" width="@@Width@@" height="@@Height@@" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<!-- TemplateEndIf -->
But the goal is that a user can add a link to a video component in the wysiwyg-editor. That way it is possible to have text - video - more text.
So the idea was tho create a custom linkresolver.
I have already the logic to get all the links and to check if they are linking to a component with a certain type. But I'm stuck on how I can replace the link with a component presentation based on a fixed component template.
Edit: I did some modifications and the code of the linkresolver is now:
XmlDocument domOutput = output.GetAsXmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("tridion", "http://www.tridion.com/ContentManager/5.0");
if (domOutput != null)
{
Logger.Debug("domOutput is not null");
foreach (XmlNode nodeCompLink in domOutput.SelectNodes("//a[@tridion:href]", nsmgr))
{
String uriCompLink = nodeCompLink.Attributes["href", "http://www.tridion.com/ContentManager/5.0"].Value;
try
{
Component linkedComponent = (Component)engine.GetObject(uriCompLink);
String title = linkedComponent.Schema.Title.ToLower();
Logger.Debug("Title: " + title);
if (title == "video")
{
string comPressentation = engine.RenderComponentPresentation(linkedComponent.Id, new global::Tridion.ContentManager.TcmUri("tcm:66-72075-32"));
Logger.Debug("comPressentation: " + comPressentation);
XmlDocument tempDoc = new XmlDocument();
tempDoc.LoadXml(comPressentation);
XmlNode tempNode = tempDoc.DocumentElement;
//change nodecomplink with component pressentation
Logger.Debug("insert component pressentation");
nodeCompLink.ParentNode.InsertAfter(domOutput.ImportNode(tempNode, true), nodeCompLink);
//remove nodecomplink
Logger.Debug("remove link");
nodeCompLink.ParentNode.RemoveChild(nodeCompLink);
}
}
catch (Exception e)
{
Logger.Error("There is an error: " + e.Message);
}
}
output.SetAsString(domOutput.OuterXml);
}
In template builder my link is correctly replaced but I still have 2 issues that I need to resolve:
- For Vimeo the componentpressentation don't seems to be valid xml => continue to investigate
- When publishing the link is not replaced with the content of the component pressentation. => solution: changing the component template to a dynamic component template and republishing the page.