Umbraco - Using GetPreValueAsString to Return the String of a Field and not its value
If you have a field in Umbraco that is getting returned as a number instead of the name, see the highlighted text below. 1 - In a Macro . 2 - In a Template.
1. IN A XSLT MACRO:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Don't change this but create a 'number' element in your -->
<!-- macro with the alias of 'numberOfItems' -->
<xsl:variable name="recordsPerPage" select="20" />
<xsl:variable name="newsPages" select="$currentPage/* [@isDoc]"/>
<xsl:variable name="pageNumber" >
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('page') <=0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="numberOfItems" select="count($newsPages)"/>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:if test="$numberOfItems > 0">
<div id="search-results" class="listing search-listing">
<xsl:variable name="thisDiscipline" select="$currentPage/discipline"/>
<xsl:if test="$thisDiscipline !=''"><h1><xsl:value-of select="string(umbraco.library:GetPreValueAsString($thisDiscipline))"/></h1> </xsl:if> <xsl:if test="$thisDiscipline =''"><h1> </h1> </xsl:if>
<xsl:for-each select="$newsPages">
<xsl:sort select="publicationDate" order="descending"/>
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<div class="int">
<div class="item">
<div class="image">
<img height="85" width="85"
alt=""
src="/media/content/types/publication.gif" />
</div>
<div class="description">
<p class="title">
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
</p>
<div class="metadata">
<span><strong>Theme</strong>: <xsl:value-of select="theme"/></span>
<span><strong>Career stage</strong>: <xsl:value-of select="careerStage"/></span>
<span><strong>Format</strong>: <xsl:value-of select="format"/></span>
<!--<span><strong>ISBN</strong>: <xsl:value-of select="iSBN"/></span>-->
</div>
<p><xsl:value-of select="documentOverview"/></p>
</div><!--Description -->
<div class="cta"> <a href="{umbraco.library:NiceUrl(@id)}">Find Out More</a>
</div>
</div>
</div>
</xsl:if>
</xsl:for-each>
</div>
<xsl:if test="$numberOfItems > $recordsPerPage">
<p id="pager">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</p>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- individual links to each page of results for the search -->
<xsl:template name="pageNumbers">
<xsl:param name="pageIndex"/>
<xsl:if test="$pageIndex != 1"> | </xsl:if>
<xsl:choose>
<xsl:when test="$pageIndex - 1 = $pageNumber">
<!-- current page -->
<strong>
<xsl:value-of select="$pageIndex"/>
</strong>
</xsl:when>
<xsl:otherwise>
<!-- other pages -->
<a>
<xsl:attribute name="href">
?page=<xsl:value-of select="$pageIndex - 1"/>
</xsl:attribute>
<xsl:value-of select="$pageIndex"/>
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$pageIndex * $recordsPerPage < $numberOfItems">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="$pageIndex + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
2. IN A TEMPLATE:
<%@ Master Language="C#" MasterPageFile="~/masterpages/Page.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="NHSNESPageContentPlaceholder" runat="server">
<!-- LEADER -->
<umbraco:Macro Alias="LeaderNormalPage" runat="server"></umbraco:Macro>
<div id='content'>
<div class='page'>
<!-- SIDE NAVIGATION -->
<div class='column-left left-nav'>
<umbraco:Macro Alias="SideNavigation" runat="server" />
</div>
<div class='column-middle page-content'>
<h1><umbraco:Item ID="Item1" field="pageName" runat="server" /></h1>
<div class="metadata">
<span><strong>Discipline:</strong>
<umbraco:Item runat="server" field="discipline" xslt="umbraco.library:GetPreValueAsString({0})" />
</span> <span><strong>Office:</strong> <umbraco:Item field="office" runat="server"></umbraco:Item>
</span>
<span><strong>Location:</strong> <umbraco:Item field="location" runat="server"></umbraco:Item>
</span>
<span><strong>Overview:</strong> <umbraco:Item field="jobOverview" useIfEmpty="jobOverview" runat="server"></umbraco:Item>You will provide operational project administration support to a range of uni- and multi-disciplinary projects within the Nursing, Midwifery & Allied Health Professions Directorate.
</span>
<span><strong>Closing date:</strong> <umbraco:Item field="closingDate" useIfEmpty="closingDate" formatAsDate="true" runat="server"></umbraco:Item>
</span></div>
<p class="subtitle"><umbraco:Item field="pageIntroduction" runat="server" /></p>
<umbraco:Item field="mainContent" runat="server" />
<umbraco:Macro Alias="NESPublicationDisclaimer" runat="server"></umbraco:Macro>
<umbraco:Macro Alias="relatedLinks" runat="server" />
</div>
<div class='column-right'>
<!-- CURRENT INITIATIVES -->
<umbraco:Macro ID="Macro4" Alias="FeaturedInitiativesBox" runat="server" />
<!-- CONTACT FINDER -->
<umbraco:Macro ID="Macro5" Alias="ContactFinderBox" runat="server" />
<!-- RELATED RESOURCES -->
<umbraco:Macro ID="Macro6" Alias="RelatedResources" runat="server" />
</div>
</div>
<div class='pre-footer'>
<a href='#nav'>Back to top</a>
</div>
</div>
</asp:Content>
1. IN A XSLT MACRO:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Don't change this but create a 'number' element in your -->
<!-- macro with the alias of 'numberOfItems' -->
<xsl:variable name="recordsPerPage" select="20" />
<xsl:variable name="newsPages" select="$currentPage/* [@isDoc]"/>
<xsl:variable name="pageNumber" >
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('page') <=0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="numberOfItems" select="count($newsPages)"/>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:if test="$numberOfItems > 0">
<div id="search-results" class="listing search-listing">
<xsl:variable name="thisDiscipline" select="$currentPage/discipline"/>
<xsl:if test="$thisDiscipline !=''"><h1><xsl:value-of select="string(umbraco.library:GetPreValueAsString($thisDiscipline))"/></h1> </xsl:if> <xsl:if test="$thisDiscipline =''"><h1> </h1> </xsl:if>
<xsl:for-each select="$newsPages">
<xsl:sort select="publicationDate" order="descending"/>
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<div class="int">
<div class="item">
<div class="image">
<img height="85" width="85"
alt=""
src="/media/content/types/publication.gif" />
</div>
<div class="description">
<p class="title">
<a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
</p>
<div class="metadata">
<span><strong>Theme</strong>: <xsl:value-of select="theme"/></span>
<span><strong>Career stage</strong>: <xsl:value-of select="careerStage"/></span>
<span><strong>Format</strong>: <xsl:value-of select="format"/></span>
<!--<span><strong>ISBN</strong>: <xsl:value-of select="iSBN"/></span>-->
</div>
<p><xsl:value-of select="documentOverview"/></p>
</div><!--Description -->
<div class="cta"> <a href="{umbraco.library:NiceUrl(@id)}">Find Out More</a>
</div>
</div>
</div>
</xsl:if>
</xsl:for-each>
</div>
<xsl:if test="$numberOfItems > $recordsPerPage">
<p id="pager">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</p>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- individual links to each page of results for the search -->
<xsl:template name="pageNumbers">
<xsl:param name="pageIndex"/>
<xsl:if test="$pageIndex != 1"> | </xsl:if>
<xsl:choose>
<xsl:when test="$pageIndex - 1 = $pageNumber">
<!-- current page -->
<strong>
<xsl:value-of select="$pageIndex"/>
</strong>
</xsl:when>
<xsl:otherwise>
<!-- other pages -->
<a>
<xsl:attribute name="href">
?page=<xsl:value-of select="$pageIndex - 1"/>
</xsl:attribute>
<xsl:value-of select="$pageIndex"/>
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$pageIndex * $recordsPerPage < $numberOfItems">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="$pageIndex + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
2. IN A TEMPLATE:
<%@ Master Language="C#" MasterPageFile="~/masterpages/Page.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="NHSNESPageContentPlaceholder" runat="server">
<!-- LEADER -->
<umbraco:Macro Alias="LeaderNormalPage" runat="server"></umbraco:Macro>
<div id='content'>
<div class='page'>
<!-- SIDE NAVIGATION -->
<div class='column-left left-nav'>
<umbraco:Macro Alias="SideNavigation" runat="server" />
</div>
<div class='column-middle page-content'>
<h1><umbraco:Item ID="Item1" field="pageName" runat="server" /></h1>
<div class="metadata">
<span><strong>Discipline:</strong>
<umbraco:Item runat="server" field="discipline" xslt="umbraco.library:GetPreValueAsString({0})" />
</span> <span><strong>Office:</strong> <umbraco:Item field="office" runat="server"></umbraco:Item>
</span>
<span><strong>Location:</strong> <umbraco:Item field="location" runat="server"></umbraco:Item>
</span>
<span><strong>Overview:</strong> <umbraco:Item field="jobOverview" useIfEmpty="jobOverview" runat="server"></umbraco:Item>You will provide operational project administration support to a range of uni- and multi-disciplinary projects within the Nursing, Midwifery & Allied Health Professions Directorate.
</span>
<span><strong>Closing date:</strong> <umbraco:Item field="closingDate" useIfEmpty="closingDate" formatAsDate="true" runat="server"></umbraco:Item>
</span></div>
<p class="subtitle"><umbraco:Item field="pageIntroduction" runat="server" /></p>
<umbraco:Item field="mainContent" runat="server" />
<umbraco:Macro Alias="NESPublicationDisclaimer" runat="server"></umbraco:Macro>
<umbraco:Macro Alias="relatedLinks" runat="server" />
</div>
<div class='column-right'>
<!-- CURRENT INITIATIVES -->
<umbraco:Macro ID="Macro4" Alias="FeaturedInitiativesBox" runat="server" />
<!-- CONTACT FINDER -->
<umbraco:Macro ID="Macro5" Alias="ContactFinderBox" runat="server" />
<!-- RELATED RESOURCES -->
<umbraco:Macro ID="Macro6" Alias="RelatedResources" runat="server" />
</div>
</div>
<div class='pre-footer'>
<a href='#nav'>Back to top</a>
</div>
</div>
</asp:Content>
Comments
Post a Comment