开发者

umbraco - masterpage: "if field is not empty then show field"

开发者 https://www.devze.com 2023-02-11 14:14 出处:网络
I\'m totally new to Umbraco and .net. I have a masterpage and a few fields - now i\'d like to show a part of the masterpage only if a specific field is not empty.

I'm totally new to Umbraco and .net. I have a masterpage and a few fields - now i'd like to show a part of the masterpage only if a specific field is not empty.

Pseudo code:

if(myField != NULL) then
<div class="something">
<umbraco:Item field="myField" runat="server"></umbraco:Item >
</div>
endif;

Andy idea how that works?

开发者_开发问答

Thanks in advance!


Thanks to the helpful umbraco irc channel i found the solution. The answer was to create a xslt file + macro (which is generated automatically).

xslt content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<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"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:variable name="myField" select="$currentPage/myField" />

<xsl:if test="$myField!= ''">
      <xsl:value-of select="$myField" />
</xsl:if>


</xsl:template>

</xsl:stylesheet>

Masterpage content:

<body>
....
<umbraco:Macro Alias="MyField" runat="server"></umbraco:Macro>
....
</body>
0

精彩评论

暂无评论...
验证码 换一张
取 消