Link to home
Start Free TrialLog in
Avatar of brendanlefavre
brendanlefavreFlag for United States of America

asked on

Get Site URL in Display Template

Currently I'm hard coding the URL for the current site, and would like to use the current context to get the proper link. Which property can I use to get the current url?

In my example, the variable "href" is being hard coded, I would like to make this a bit more dynamic.

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head>
<title>Unique Item Id Results</title>

<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:MasterPageDescription msdt:dt="string">Displays the inline result body elements that are common to all results.</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:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor','ListUrl':'ListUrl','ListItemId':'ListItemId','ListId':'ListId','SiteId':'SiteId','WebId':'WebId','LegacyItemId':'LegacyItemId'</mso:ManagedPropertyMapping>
<mso:_dlc_DocId msdt:dt="string">5HUVTUKZTP46-1-223</mso:_dlc_DocId>
<mso:_dlc_DocIdItemGuid msdt:dt="string">27aca1c4-1300-489b-bf9c-71edbbb401b2</mso:_dlc_DocIdItemGuid>
<mso:_dlc_DocIdUrl msdt:dt="string">http://intranet/sites/jwtest/_layouts/15/DocIdRedir.aspx?ID=5HUVTUKZTP46-1-223, 5HUVTUKZTP46-1-223</mso:_dlc_DocIdUrl>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
<body>
    <div id="Item_CommonItem_Body">
<!--#_
        var id = ctx.CurrentItem.Id;
		var legacyItemId = ctx.CurrentItem.LegacyItemId;
		var listUrl = ctx.CurrentItem.ListUrl;
		var listItemId = ctx.CurrentItem.ListItemId;
		var listId = ctx.CurrentItem.ListId;
		var siteId = ctx.CurrentItem.SiteId;
		var webId = ctx.CurrentItem.WebId;
        	var title = ctx.CurrentItem.Title;
		var parentLink = ctx.CurrentItem.ParentLink;

		var href = "http://intranet/sites/jwtest/";
		
		var action = "_layouts/15/CopyUtil.aspx?Use=id&Action=dispform";
		var completeLink = String.format('<a href="{0}{1}&itemId={2}&listId={3}&siteId={4}&webId={5}">{6} </a>', href, action, listItemId, $htmlEncode(listId), $htmlEncode(siteId), $htmlEncode(webId), title);

		
_#-->				
    
            <div>
				<div><span><h1>Unique Item Results</h1></span></div>
					<div>
						<ul>
							<li>Title: _#= title =#_</li>
							<li>Legacy ID: _#= legacyItemId =#_</li>
							<li>List URL: _#= listUrl =#_</li>
							<li>List Item ID: _#= listItemId =#_</li>
							<li>List ID: _#= listId =#_</li>
							<li>Site ID: _#= siteId =#_</li>
							<li>Web ID: _#= webId =#_</li>
							<li>Parent Link: _#= parentLink =#_</li>
							<li>Completed URL: _#= completeLink =#_ </li>
						</ul>
					</div>
     
            </div>

	</div>
</body>
</html>

Open in new window


Cheers,
Brendan
ASKER CERTIFIED SOLUTION
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial