I'm trying to get a SP.UI.ModalDialog to work if a user clicks on a link on a site collection. I'm implementing the code in my item display template. Unfortunately, clicking on the link does not pop up a modal dialog window. Nothing happens and I'm not getting an error message or anything.
The relevant display template code looks like this:
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<title>News_TableItem</title>
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:MasterPageDescription msdt:dt="string">Displays a result tailored for a person.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">; #SearchResults;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:CrawlerXSLFile msdt:dt="string"></mso:CrawlerXSLFile>
<mso:ManagedPropertyMapping msdt:dt="string">Title:Title, Path:Path, EditorOWSUSER:EditorOWSUSER, LastModifiedTime:LastModifiedTime, BlogArtikeldatum:BlogArtikeldatum, BlogLeadtext:BlogLeadtext, BlogKommentare:BlogKommentare, BlogLikes:BlogLikes, ParentLink:ParentLink, FileType:FileType, IsContainer:IsContainer, SecondaryFileExtension:SecondaryFileExtension</mso:ManagedPropertyMapping><mso:HtmlDesignPreviewUrl msdt:dt="string"></mso:HtmlDesignPreviewUrl>
<mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded>
<mso:HtmlDesignStatusAndPreview msdt:dt="string">[...]NewsCenter.html, Konvertierung erfolgreich.</mso:HtmlDesignStatusAndPreview>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
<body>
<div id="Item_WebPage">
<!--#_
if (!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)) {
function GetFormattedDate() {
var articleDate = new Date(ctx.CurrentItem.BlogArtikeldatum);
var day = ("0" + format(articleDate.getDate())).slice(-2);
var month = ("0" + format(articleDate.getMonth() + 1)).slice(-2);
var year = articleDate.getFullYear();
return day + "." + month + "." + year;
}
//Check if LikeCount is 0
var likecount = 0
if (ctx.CurrentItem.BlogLikes != null) {
likecount = ctx.CurrentItem.BlogLikes;
}
function modalArticle() {
var options = SP.UI.$create_DialogOptions();
options.width = 1200;
options.height = 1200;
options.allowMaximize = true;
options.url = ctx.CurrentItem.Path + '&IsDlg=1';
SP.UI.ModalDialog.showModalDialog(options);
}
ctx.currentItem_modalArticle = modalArticle();
_#-->
<div class='news center clearfix overview'>
<div class='newsContent'>
<div class='newsHeadline'>
<h4><a>_#= ctx.CurrentItem.Title =#_</a> <span class='super'> _#= GetFormattedDate() =#_ | <i class="fa fa-thumbs-up"></i> _#= likecount =#_ </span> </h4>
</div>
<div class="leadtext">
_#= ctx.CurrentItem.BlogLeadtext =#_
</div>
</div>
</div>
<!--#_
}
_#-->
</div>
</body>
</html>
For the line where I'm calling the code I also tried:
<h4><a onclick="SP.UI.ModalDialog.showModalDialog(modalArticle());" href="javascript:void(0)">_#= ctx.CurrentItem.Title =#_</a></h4>
<h4><a onclick="SP.UI.ModalDialog.showModalDialog(modalArticle())" href="javascript:void(0)">_#= ctx.CurrentItem.Title =#_</a></h4>
<h4><a onclick=" =#_ SP.UI.ModalDialog.showModalDialog(modalArticle()) =#_ " href="javascript:void(0)">_#= ctx.CurrentItem.Title =#_</a></h4>
The last version is the only one that actually does something. It opens all links that exist on the page at once which is about 30 on that page. I'm assumung that wrapping the function in #= =# effetively disables the .onclick() event and executes the function for all links.
Any idea why it's not opening or how I could debug this?
Thanks a lot!