Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have the following code inside a template. I would like to hide if the user didnt put any text in for the objectivebox field
<div class="box"> <h2>Objective</h2> <p><umbraco:Item field="objectivebox" runat="server" /></p> </div>
Hi Donald,
Since you have posted it in XSLT, I assume that you are going to use XSLT. So first go to the developer section a create a new XSLT file, and create a associated marco.
And then your XSLT file should look like this:
<?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:Examine="urn:Examine" xmlns:umbraco.contour="urn:umbraco.contour" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Examine umbraco.contour "><xsl:output method="xml" omit-xml-declaration="yes"/><xsl:param name="currentPage"/><xsl:template match="/"><!-- start writing XSLT --><xsl:if test="$currentPage/objectivebox !=''"> <div class="box"> <h2>Objective</h2> <p><xsl:value-of select="$currentPage/objectivebox" /></p> </div></xsl:if></xsl:template></xsl:stylesheet>
If you call your XSLT something like this Objectivebox then in your template where the data should be print you need to insert this:
<umbraco:Macro Alias="Objectivebox" runat="server" />
Hope this helps, if you have any further questions keep asking them.
/Dennis
It works great but the only issue I see is when I do type content in it shows up like <p>hi</p>
<p>hi</p>
Okay then add disable-output-escaping="yes" to the value-of select.
<?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:Examine="urn:Examine" xmlns:umbraco.contour="urn:umbraco.contour" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Examine umbraco.contour "><xsl:output method="xml" omit-xml-declaration="yes"/><xsl:param name="currentPage"/><xsl:template match="/"><!-- start writing XSLT --><xsl:if test="$currentPage/objectivebox !=''"> <div class="box"> <h2>Objective</h2> <p><xsl:value-of select="$currentPage/objectivebox" disable-output-escaping="yes" /></p> </div></xsl:if></xsl:template></xsl:stylesheet>
Hi Donald
Just some additional info to Dennis' answer..
In the condition check you can also use normalize-space() to ensure the field doesn't just contain whitespaces: http://our.umbraco.org/documentation/Reference/Api/UmbracoLibrary/
<xsl:if test="normalize-space($currentPage/objectivebox)"> <div class="box"> <h2>Objective</h2> <p><xsl:value-of select="$currentPage/objectivebox" disable-output-escaping="yes" /></p> </div> </xsl:if>
Cheers,Bjarne
Thank you so much! It works perfectly!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Hide Div if field is empty
I have the following code inside a template. I would like to hide if the user didnt put any text in for the objectivebox field
Hi Donald,
Since you have posted it in XSLT, I assume that you are going to use XSLT. So first go to the developer section a create a new XSLT file, and create a associated marco.
And then your XSLT file should look like this:
If you call your XSLT something like this Objectivebox then in your template where the data should be print you need to insert this:
Hope this helps, if you have any further questions keep asking them.
/Dennis
It works great but the only issue I see is when I do type content in it shows up like
<p>hi</p>
Hi Donald,
Okay then add disable-output-escaping="yes" to the value-of select.
/Dennis
Hi Donald
Just some additional info to Dennis' answer..
In the condition check you can also use normalize-space() to ensure the field doesn't just contain whitespaces: http://our.umbraco.org/documentation/Reference/Api/UmbracoLibrary/
Cheers,
Bjarne
Thank you so much! It works perfectly!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.