Make <div> disappear when theres no content in it Options
electricric
Posted: Friday, August 29, 2008 11:03:30 AM
Rank: Newbie

Joined: 8/25/2008
Posts: 16
Location: Germany

Hi folks,


I want a Navigation-Box surrounded by div-tags to disappear when theres no content in it.
It works for me with the GetItem-field property for the content with "insertTextbefore" and "insertTextafter", like this:

Code:

<?UMBRACO_GETITEM field="sidebarcontent" insertTextBefore="&lt;div class=&quot;SidebarContent&quot;&gt;" insertTextAfter="&lt;/div&gt;" recursive="true"/>


The insertTextBefore is : <div class="SidebarContent">
The insertTextAfter is just: </div>
I don't know why umbraco makes such a mess of my markup when entered in this field, but it works fine this way!


Now it gets a little more complicated, as i have another SidebarContent-div, but this time with the GETITEM-field AND a Macro in it (for Navigation-Links), like this:
Code:

<div class="SidebarContent">
      <?UMBRACO_GETITEM field="sidebarcontent" recursive="true"/>       
      <?UMBRACO_MACRO macroAlias="SidebarNavigation"></?UMBRACO_MACRO>
  </div>


When i just insert the Macro in the "inserttextAfter"-field of the GETITEM, it doesn't works out/fails to display, so i guess one cannot insert a macro in one of this fields.
However, the Macro itselfs doesn't seem to have "insertTextBefore"/"insertTextAfter"-properties, so i can't put the divs in it either.

The result is that when theres no content in the GETITEM and the Macro, there are visible borders of the div on the frontend, what i don't want. I wan't the box to completly disapear.


I also wonder what could be written between the Macro tags and if it could help me out?
Code:

<?UMBRACO_MACRO macroAlias="blabla"> What could i write in here? </?UMBRACO_MACRO>



Anyone an idea how to solve this problem?


Greetings,

Electric-Ric
darrenjferguson
Posted: Friday, August 29, 2008 1:29:41 PM

Rank: Fanatic

Joined: 3/19/2008
Posts: 229
Location: London, UK
What type of Macro is this? (XSLT/.net)

You'll probably need to move the logic to conditionally display the div tag to the Macro itself.

Darren Ferguson - Umbraco level 2 certified
www.darren-ferguson.com - www.fergusonmoriyama.com
electricric
Posted: Friday, August 29, 2008 2:23:26 PM
Rank: Newbie

Joined: 8/25/2008
Posts: 16
Location: Germany
Edit: I think my main problem is, that these <div>-Box could be filled with the Macro-Links, or the GETITEM-Text,both (but without doubled <divs>) or nothing (thus disappearing). This makes it difficult to me to say how i could insert this <div> stuff best.

It's a XSLT-Macro. It walkes the nodes for documents that have the attributes "sidebarbox = 18" (=>display Link to Document in Sidebar-Navigation: yes/no) and the UmbracoNaviHide -property disabled.
It then makes an unordered list out of the found documents.

Because i'm quite new to the XSLT-Scripting, this Script is basically written by Dirk (Forumuser), so i just made a few modifications. It looks like this:

Code:

<?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"
    exclude-result-prefixes="msxml umbraco.library">


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

<xsl:param name="currentPage"/>

<xsl:template match="/">

<!-- The fun starts here -->
<xsl:choose>
<xsl:when test="count($currentPage/node) &gt; 0">
<ul>
<xsl:for-each select="$currentPage/../node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
        </a>
    </li>
</xsl:for-each>
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:for-each select="$currentPage/../node [string(data [@alias='umbracoNaviHide']) != '1' and data [@alias = 'sidebarbox'] = '18']">
   
    <li>
         <a href="{umbraco.library:NiceUrl(@id)}">
           <xsl:if test="$currentPage/@id=current()/@id">
       <xsl:attribute name="class">selected</xsl:attribute>   
           </xsl:if>         
         <xsl:value-of select="@nodeName"/>
        </a>
    </li>
</xsl:for-each>
</ul>

</xsl:otherwise>
</xsl:choose>

</xsl:template>
</xsl:stylesheet>



Greetings,
Electric-Ric
Dirk
Posted: Friday, August 29, 2008 3:40:32 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,136
Location: Belgium
Hi electricric,

Just a quick thought:

All macro's are fed with $currentPage parameter, which is the xml fragment from the current node!

Code:
<div class="SidebarContent">
      <?UMBRACO_GETITEM field="sidebarcontent" recursive="true"/>       
      <?UMBRACO_MACRO macroAlias="SidebarNavigation"></?UMBRACO_MACRO>
</div>


First statement (GET_ITEM) is fetching the field sidebarcontent, also from the current node!

If that is true, you could combine the two in your xslt macro, right?

Solution then would be:

Code:
<?UMBRACO_MACRO macroAlias="SidebarNavigation"></?UMBRACO_MACRO>


Only this statement in your template. And within the macro, you'd check whether the current node property sidebarcontent AND whether info is available in the list using the count() statement as you're already doing it now.

Code:
<xsl:when test="$currentPage/@sidebarcontent != '' and count($currentPage/node) &gt; 0">
...


Does that make sense? Darren is right, you should move the logic out of the template and into the macro.

Hope that helps.

Regards,
/Dirk





level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.