0

I've created a display template based off the Item_Person template in the SharePoint 2013 on Premises application. This template list the Departments, Branch Location and Regions. On the display template they are shown like the example below.

_#= displayName =#_
_#= displayJtitle =#_ 
_#= displayDept =#_  (Department)
_#= displayol =#_    (Branch Location)
_#= displayreg =#_   (Region)

I have two questions but they are similar.

I am looking to only show Regions for employees who's User Profile field Region does not show "Non Region", so for a corporate employee they will not have a Region, but a Branch Employee will have a region. In our HR System, there were unable to leave this field blank so they chose to just put in "Non Region" for corporate employees. How can I filter out a User that does not have a region and not display that area.

<!--#_
  var encodedreg = $htmlEncode(ctx.CurrentItem.Region)
  var displayreg = Srch.U.getSingleHHXMLNodeValue(hhProps, "Region")
  if ($isEmptyString(displayreg)) { displayreg = encodedreg }
 _#-->
  <!--#_ if(encodedreg != "Non Region") {   _#-->
    <div id='region'>Region: </span> _#= displayreg =#_ </div>
  <!--#_ } _#-->

Next, we have one Branch that has a Mailing Address that is not it's Physical Address. Is there a way I can look for the Branch Name and only show the Mailing Address if its that particular branch?

<!--#_
  var encodedol = $htmlEncode(ctx.CurrentItem.OfficeLocation)
  var displayol = Srch.U.getSingleHHXMLNodeValue(hhProps, "OfficeLocation") 
  if ($isEmptyString(displayol)) { displayol = encodedol }
_#-->
   <!--#_if(encodedol == "Branch Main") {    _#--> 
    <div id='MailAdd'>Mailing Address: </span>P.O. Box ####</div>
  <!--#_ } _#-->
0

If you check this link. You can see conditional statements are written as

<!--#_
if(!linkURL.isEmpty)
{
_#-->
     <a class="cbs-pictureImgLink" href="_#= linkURL =#_" title="_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_" id="_#= pictureLinkId =#_">
<!--#_
}
_#-->

Try this

<!--#_
if(!encodedol.isEmpty && encodedol.indexOf('Branch Main') >= 0)
{
_#-->
     <div id='MailAdd'>Mailing Address:</div>
<!--#_
}
_#-->
  • How can I do this with a specific variable, so not looking to see if its empty but to see if the branch name is "Branch Main" @Amal Hashim – Alvina Nov 20 '14 at 18:29
  • @Alvina I have updated my answer – Amal Hashim Nov 20 '14 at 18:38
  • OMG Yes it worked. Thank you so much. So the Index of looks at specific variables? – Alvina Nov 20 '14 at 18:54
  • @Alvina indexof will basically look the entire string. so if the string has leading or trailing spaces it works fine. – Amal Hashim Nov 20 '14 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.