Archive for category Umbraco

Giving Umbraco custom tree’s children!

This was something i was looking for for a while- turns out it is buried deep in their forums;

As shown in their own example (I’ve reblogged here incase the page ever moves or dissapears!!)

Turns out it’s just a case of setting the “source” property of the XmlTreeNode.

public override void Render(ref XmlTree tree)
{
           
            Dictionary.DictionaryItem[] tmp;
        //this.id is set when the tree.aspx creates this object. 
        //It is the nodeID that is passed in via the tree service parameters (i.e. the query string)
        //this checks if the id is the StartNodeID (root node), if it’s not then this will 
        //look up the child nodes for the current dictionary item.
            if (this.id == this.StartNodeID)
                tmp = Dictionary.getTopMostItems;
            else
                tmp = new Dictionary.DictionaryItem(this.id).Children;

            foreach (Dictionary.DictionaryItem di in tmp)
            {
             XmlTreeNode xNode = XmlTreeNode.Create(this);
             xNode.NodeID = di.id.ToString();
             xNode.Text = di.key;
             xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id);
             xNode.Icon = "settingDataType.gif";
             xNode.OpenIcon = "settingDataType.gif";
             //if there is no children, then set the source to an empty string
//this will ensure that there is no expand button for this node when it is 
//rendered. Otherwise, set the source to the tree service url by using
//the BaseTree’s GetTreeServiceUrl method
             xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : "";
             tree.Add(xNode);
            }
}

3 Comments

Umbraco Installation – folder permissions setup

Just a real quick batch script i knocked up which sets the appropriate permissions to the various folders in the root of a fresh umbraco install- just drop this into a batch file, and run it from the root of your umbraco install;

REM 2009.10.22 SY - Set permissions- user/ folders from "Install Umbraco 4 on Windows Vista" guide
icacls app_code /grant "Network Service":(OI)(CI)(F)
icacls bin /grant "Network Service":(OI)(CI)(F)
icacls config /grant "Network Service":(OI)(CI)(F)
icacls css /grant "Network Service":(OI)(CI)(F)
icacls data /grant "Network Service":(OI)(CI)(F)
icacls masterpages /grant "Network Service":(OI)(CI)(F)
icacls media /grant "Network Service":(OI)(CI)(F)
icacls python /grant "Network Service":(OI)(CI)(F)
icacls scripts /grant "Network Service":(OI)(CI)(F)
icacls umbraco /grant "Network Service":(OI)(CI)(F)
icacls usercontrols /grant "Network Service":(OI)(CI)(F)
icacls xslt /grant "Network Service":(OI)(CI)(F)
pause

No Comments

Paged List of Child Nodes in Umbraco

We just started looking at Umbraco- and so I’m delving into Macro’s – these are the packaged up chunks of functionality which make your site actually do things and either take the form of XSLT files which process and spit out the contents of your database, or dot net controls.

I found an excellent example XSLT that allows you to create a paginated list of child nodes over on Tim Geyssens “nibble” blog, and I’ve modified it ever so slightly to stop the numerical index rendering if the pagecount is less than 2- so thought I would re-post it!


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&amp;amp;amp;#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="/">

    <xsl:variable name="recordsPerPage" select="/macro/recordsPerPage"/>
    <xsl:variable name="pageNumber" >
      <xsl:choose>
        <!-- first page -->
        <xsl:when test="umbraco.library:RequestQueryString('page') <= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
        <!-- what was passed in -->
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:variable> &amp;amp;amp;nbsp;

    <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>

    <!-- The fun starts here -->
    <ul>
      <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>

            </a>
          </li>
        </xsl:if>
      </xsl:for-each>
    </ul>

    <xsl:if test="$pageNumber > 0">
      <a href="?page={$pageNumber -1}">previous </a>
    </xsl:if>

<xsl:if test="($numberOfRecords > $recordsPerPage)">
    <xsl:call-template name="for.loop">
      <xsl:with-param name="i">1</xsl:with-param>
      <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
      <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
    </xsl:call-template>
</xsl:if>

    <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)">
      <a href="?page={$pageNumber +1}">next</a>
    </xsl:if>
  </xsl:template>

  <xsl:template name="for.loop">

    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i <= $count - 1">

      <xsl:if test="$page != $i">
        <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >

          <xsl:value-of select="$i" />
        </a>
      </xsl:if>

      <xsl:if test="$page = $i">

        <xsl:value-of select="$i" />

      </xsl:if>
    </xsl:if>
    <xsl:if test="$i <= $count - 1">
      <xsl:call-template name="for.loop">
        <xsl:with-param name="i">
          <xsl:value-of select="$i + 1"/>
        </xsl:with-param>
        <xsl:with-param name="count">
          <xsl:value-of select="$count"/>
        </xsl:with-param>
        <xsl:with-param name="page">
          <xsl:value-of select="$page"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

2 Comments