Nibble

Archive for the 'Uncategorized' Category


Updating the locator package to support umbraco 4.5 0

As you may know there are some changes in umbraco 4.5 that might require some packages to be updated in order to be compatible with umbraco 4.5. This post outlines what I did to update the locator package with 4.5 support.

What’s important for me is that I don’t want multiple versions of the code/package depending on the umbraco version but would like to handle that in the code/installer instead. So that I have a single package that can be used on both 4.0.X and 4.5.

Identifing what schema the site is running on

In the locator package there is an xslt file to transform the results and also in the code there are several actions that manipulate the content xml, so before I can do any updates I need to know what schema the current site is using.

In umbraco 4.5 there is a new setting UmbracoSettings.UseLegacyXmlSchema (which is pulled from the /config/umbracoSettings.config), this isn’t there in umbraco version older then 4.5, so if you try to get that value and it fails because of a MissingMethodException then it should be an older version then 4.5 (and thus on the old schema)

bool useLegacySchema = true;
try { useLegacySchema = Utility.UseLegacySchema; }
catch (MissingMethodException) { }


Updating the code

In the locator package I manipulate the content xml and add some nodes (extra properties on documents) on the fly so depending on the schema I need to add

<data alias=”myAlias”>value</data> (old schema) or simply <myAlias>value<myAlias> (new schema).

After the update the code that does that looks like this:

bool useLegacySchema = true;
try { useLegacySchema = Utility.UseLegacySchema; }
catch (MissingMethodException) { }
XmlElement distanceNode =
content.CreateElement(useLegacySchema ? "data" : "distance");
distanceNode.InnerText = distance.ToString(Utility.NumberFormatInfo);
if (useLegacySchema)
{
XmlAttribute aliasAttribute = content.CreateAttribute("alias");
aliasAttribute.Value = "distance";
distanceNode.Attributes.Append(aliasAttribute);
}
node.AppendChild(distanceNode);


Updating the package, installing the correct xslt file

The locator package installs an xslt file (LocatorResults.xslt) that is used to transform the search results. Depending on what schema the current site is using it needs to install the correct version, this is handled by a custom package action.

In the package I simply include an additional xslt file LocatorResultsNewSchema.xslt (the new schema version)

But I let the installer place this in the /data/packages/temp directory

So in the package.xml I have this part:

<file>
<guid>LocatorResults.xslt</guid>
<orgPath>/xslt</orgPath>
<orgName>LocatorResults.xslt</orgName>
</file>
<file>
<guid>LocatorResultsNewSchema.xslt</guid>
<orgPath>/data/packages/temp</orgPath>
<orgName>LocatorResultsNewSchema.xslt</orgName>
</file>

Which will copy the LocatorResults.xslt file(using the old schema) in the package to the /xslt directory and the LocatorResultsNewSchema.xslt(using the new schema) to the /data/packages/temp directory.

At this point the xslt using the old schema is installed in the /xslt directory, so now if the site is using the new schema I simply need to move the LocatorResultsNewSchema.xslt file to /xslt/LocatorResults.xslt.

That’s done with a custom package action

The package action Xml looks like this:

<Action runat="install" alias="addNewSchemaContentToFile">
<source>/data/packages/temp/LocatorResultsNewSchema.xslt</source>
<target>/xslt/LocatorResults.xslt</target>
</Action>

The source node contains the path to the new schema xslt file and the target node contains the path to the location of the xslt file to overwrite.

The package action then simply checks if the current site is using the new schema, if it is it deletes the existing xslt file (the one using the old schema) and then moves the xslt file that’s using the new schema to that location. If the site is on the old schema it will simply delete the new schema xslt file.

public bool Execute(string packageName, System.Xml.XmlNode xmlData)
{
string basePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
string sourceFile = xmlHelper.GetNodeValue(xmlData.SelectSingleNode("source"));
string targetFile = xmlHelper.GetNodeValue(xmlData.SelectSingleNode("target"));
try
{
if (!Utility.UseLegacySchema)
{
if (File.Exists(basePath + sourceFile))
{
if (File.Exists(basePath + targetFile))
File.Delete(basePath + targetFile);
File.Move(basePath + sourceFile, basePath + targetFile);
}
return true;
}
else
{
File.Delete(basePath + sourceFile);
return true;
}
}
catch(MissingMemberException)
{
File.Delete(basePath + sourceFile);
return true;
}
}

 

That’s what it took to update the locator package (in this case it was all related to the schema changes), the new package is available on the locator project page at our.umbraco.org and sourcecode is available on codeplex.

Umbraco courses landed in the Benelux 4

Be among the first to get certified in the Benelux, registration just opened for the first round of official umbraco courses held in Antwerp, Belgium.

Level 1 is running on 3-4 May and level 2 on 5-6 May.

These are the same courses taught throughout the world and will teach you everything you need to know to attain your Umbraco Certification.

Secure your seat today!
http://umbraco.org/training/training-in-benelux

Umbraco Contour is out ! 0

The last couple of months (since joining the umbraco corp) I’ve been involved in the development of Umbraco Contour.

It turned out to be an amazing product! Detailed info and some screencast can be found on the official Contour product page.

You can also try Contour before buy, by installing a trial straight from the package repository.

image

image

image

Example for adding a PDF generator to your umbraco site 0

Some time ago I created a solution for generating pdf documents from your umbraco content (and from the outputted html). I always wanted to make a package out of this but since the project relies on the commercial pdf generating library ABCpdf this isn’t possible. The main reason for using ABCpdf is that it’s html to pdf options are pretty decent.

So instead of releasing a package I’ll share the sourcecode and I’ll give an overview of how to use it.

Download: PDFGen sourcecode

Installation

Once you have ABCpdf installed (it’s possible to download a trail and you can also apply for a free license) the installation is just a mather of dropping some files in your umbraco instance.

  • Drop PDFGen.dll in the /bin folder
  • Drop PDFGen.aspx in the /umbraco
  • Drop PDFGen.config in the /config folder

Setup

First you’ll need to define a pdf template, this can be done in the PDFGen.config file which should
be in the /config folder.
Lets look at an example config file:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<PDFGen PermitPrint=”False” PermitExtractContent=”False”>
<!– Header–>
<Text FontName=”Arial” FontSize=”12″ FontColor=”0,0,0″ X1=”20″ Y1=”40″ X2=”500″ Y2=”700″
IsRecurring=”true”>my header text</Text>
<Image File=”/media/950/joblistpdfhead.jpg” X=”20″ Y=”670″ Width=”570″ Height=”100″ IsRecurring=”true”/>
<!– Content –>
<Property RequestParam=”test” PropertyAlias=”title;@createDate” FontName=”Arial” FontSize=”18″
FontColor=”0,0,0″ X1=”25″ Y1=”620″ X2=”500″ Y2=”650″ IsRecurring=”false”>{0} - {1}</Property>
<Property RequestParam=”" PropertyAlias=”info” FontName=”Arial” FontSize=”11″ FontColor=”0,0,0″ X1=”25″
Y1=”180″ X2=”530″ Y2=”630″ IsRecurring=”false”></Property>
<Property RequestParam=”" PropertyAlias=”linkURL” FontName=”Arial” FontSize=”11″ FontColor=”0,0,0″
X1=”40″ Y1=”715″ X2=”520″ Y2=”740″ IsRecurring=”false”></Property>
<!– Footer –>
<Text FontName=”Arial” FontSize=”6″ FontColor=”0,0,0″ X1=”25″ Y1=”20″ X2=”500″ Y2=”30″
IsRecurring=”true”>Copyright mysite 2009 — All Rights Reserved.</Text>
</PDFGen>

After the xml declaration (yes the config file is an xml file) you have the PDFGen root node.
On this node you can set wether the generated pdf files are printable and if it is possible to extract
content (copy,paste).

<PDFGen PermitPrint=”False” PermitExtractContent=”False”>

The child nodes of the root PDFGen node will be used to define the pdf. There are a couple of
possibilities:

  • Text
  • Image
  • Property
  • RenderedOutput

Text nodes

<Text FontName=”Arial” FontSize=”12″ FontColor=”0,0,0″ X1=”20″ Y1=”40″ X2=”500″ Y2=”700″
IsRecurring=”true”>my header text</Text>

A text node is used to add some static text on the pdf document it has several attributes

  • FontName: name of the font family that will be used
  • FontSize: size of the font
  • FontColor: color of the font
  • X1,Y1,X2,Y2: these are the coordinated used to define a box where the text will be placed
  • IsRecurring: if this is set to true the text will appear on each page (used for headers and
    footers)
  • The inner text is the static text that will be placed on the pdf (it is possible to add html).

Image nodes

<Image File=”/media/950/joblistpdfhead.jpg” X=”20″ Y=”670″ Width=”570″ Height=”100″ IsRecurring=”true”/>

An image node is used to add an image to the pdf document.

An overview of it’s attributes:

  • File: path to the image
  • X,Y: coordinated of the image
  • Width: width of the image
  • Height: height of the image
  • IsRecurring: if this is set to true the image will appear on each page (used for headers and
    footers)

Property nodes

<Property RequestParam=”test” PropertyAlias=”title;@createDate” FontName=”Arial” FontSize=”18″
FontColor=”0,0,0″ X1=”25″ Y1=”620″ X2=”500″ Y2=”650″ IsRecurring=”false”>{0} – {1}</Property>

A property node is used to add umbraco content node property data to the pdf document.

An overview of it’s attributes:

  • RequestParam: if this is empty the default request param id will be used, if you want to use
    another one define it here
  • PropertyAlias: alias of the property (possible to add multiple separated by semicolon)
  • FontName: name of the font family that will be used
  • FontSize: size of the font
  • FontColor: color of the font
  • X1,Y1,X2,Y2 :these are the coordinated used to define a box where the text will be placed
  • IsRecurring :if this is set to true the text will appear on each page (used for headers and
    footers)

The innertext can be used to add some static text around the property or if you have multiple
propertyaliases you must define how they will be placed (simular to string.format).

 

RenderedOutput nodes

<RenderedOutput RequestParam=”" Template=”" X1=”25″ Y1=”620″ X2=”500″ Y2=”650″ IsRecurring=”false” />

This will fetch the rendered output of a page, if no requestparam is used it will use the id one and if no template alias is defined it will use that default template of that page.

An overview of it’s attributes:

  • RequestParam: if this is empty the default request param id will be used, if you want to use
    another one define it here
  • Template: template alias to use, if this is empty the default template of the document will be used
  • X1,Y1,X2,Y2 :these are the coordinated used to define a box where the text will be placed
  • IsRecurring :if this is set to true the text will appear on each page (used for headers and
    footers)

Usage

Once installed and if you have a working config file. You can use pdfgen by calling /umbraco/pdfgen.aspx?id=1234 (the id is the id of the umbraco document).

If you have defined other RequestParams in your config file (like headerid) you just need to do:
/umbraco/pdfgen.aspx?id=1234&headerid=2345

It’s also possible to have multiple config files (just copy the pdfgen.config) if you want to use anohter config file you can do it like this:

/umbraco/pdfgen.aspx?id=1234&pdfconfig=pdfconfigcopy.config

pdfconfigcopy.config is the filename of the configfile (must be in the /config dir)

New Package - Locator 4

Add a ‘find the nearest shop/dealer/….’ to your site in a mather of minutes with this umbraco package.

  • Full control over the output (using xslt)
  • Easy to customize
  • Supports multiple domains and multilingual sites

Example of implementation (early screencast and demo at http://lab.nibble.be/):

 

Using the package:

After installation the first thing you need to do is to setup the Nibble.Umb.Locator.config file. This can be done be editing the file or you can also do this in the settings of the Locator datatype that should have been added by the installer.

locatordatatype

The config file is basicly just used to store the different google maps api keys.

Once this is setup the next step is to add a results page (or alternative template), this is the page where the search result will be displayed.

On that template you’ll need to add the Locator macro

locatormacro

There are several parameters:

  • XPath: here you’ll need to supply some xpath that will select the nodes you want to include in the search
  • Location Alias: if the coordinates are stored on the nodes you can supply the alias of the property (you can use the included locator datatype, or it should also work with Darren’s map/place datatype)
  • Use Address: if the coordinates are not stored on the nodes but you want to use the address instead, set this to true (this is only recommended when you don’t have a lot of nodes to search)
  • Address Aliases: when you have the Use Address set to true, you’ll need to supply the alias of the property wich contains the address, when the address is in multiple properties you need to supply a semicolon seperated list
  • Results Xslt: by default the package installs a xslt file this is used to transform the results, if you want to use another one, just speficy the name
    Address Extra: if you only want to search in a certain region, you can specify a string that will be appended to the user’s search (so for UK you would append , UK)
  • Unit in Km: if you want the distance in KM instead of miles …
  • Multiple Results Caption: if there are multiple results found for the location that is entered by the user he will be presented with a radio button list where he’ll have to choose the correct one.

Both Address Extra and Multiple Results Caption support use of dictionary items (so you can use #itemname).

With the marcro in place the final step if to setup a form that will post to the page containing the macro.

<form method=”get” action=”/dealers/LocatorResult.aspx”>
            <fieldset>
                 <label for=”s”>Address/postcode: </label>
                
                <input type=”text” name=”s” />
                
                 <label for=”s”>Radius: </label>
                <select name=”radius”>
                <option value=”0″>Please select</option>
                <option value=”100″>100 miles</option>
                <option value=”1000″>1000 miles</option>
                <option value=”10000″>10000 miles</option>
                </select>
 
 
                <button type=”submit”><span>Go</span></input>
            </fieldset>
        </form>

 

You can download the package on Our Umbraco (Umbraco’s new community site), sourcecode is available on codeplex.

Alternative page for IPhone on your umbraco site 8

Since umbraco allows you to have full control over the output it’s dead simple to create an alternative page for IPhone on your umbraco site. I used this isite template (download) by Joe Hewitt (many others around like here and here) and had a page up in 20 minutes (for the blog package, it lists the posts and also features a search).

After importing the files from the isite template the first step is to create a new template (that will be our iphone page).

To redirect iphone visitors I used this javasscript snippet. My blog is located at /blog.aspx and the template is called iphone so I just call that page with the new template by using /blog/iphone.aspx (some info on alternative templates).

 

<script language=javascript>
if((navigator.userAgent.match(/iPhone/i))||
(navigator.userAgent.match(/iPod/i)))
{
    document.location.href=‘/blog/iphone.aspx’;
}
</script>

 

On the template I replaced the static content from the isite and placed an xslt macro that will list all blog posts.

<ul id=“blog” title=“Umlaut.be” selected=“true”>
<xsl:for-each select=“$currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘Blog’]//node [@nodeTypeAlias = ‘BlogPost’]”>
<xsl:sort select=“@createDate” order=“descending” />
      <li><a href=“#{@id}”><xsl:value-of select=“@nodeName”/></a></li>
</xsl:for-each>
</ul>
 
<xsl:for-each select=“$currentPage/ancestor-or-self::node [@nodeTypeAlias = ‘Blog’]//node [@nodeTypeAlias = ‘BlogPost’]”>
<xsl:sort select=“@createDate” order=“descending” />
    <div id=“{@id}” class=“panel” title=“Umlaut.be”>
        <h2><xsl:value-of select=“@nodeName”/></h2>
            <xsl:value-of select=“data [@alias = ‘bodyText’]” disable-output-escaping=“yes”/>
        </div>
</xsl:for-each>

 

umbracoiphone1 

umbracoiphone2

umbracoiphone3

And that’s it, it should be in the next version of the blog package.

Getting started with umbraco v4 2

Yesterday umbraco 4 was released, this post is an updated version of the getting started with umbraco one I did some time ago.

What is umbraco screencast

Download:

You can always find the latest umbraco release on codeplex

http://www.codeplex.com/umbraco/Release/ProjectReleases.aspx

Installation:

Install umbraco 4 on Windows Vista
Install umbraco 4 on “localhost” - simplified
Screencast 1
Screencast 2 (installation in 200 seconds)

Basics:

Document types:

Umbraco basics: document types by umbraco founder Niels Hartvig - part 1, part 2
Document Types Explained
Screencast

New feature in v4, master document types

Templates:

Screencasts on v4 masterpages by Warren Buckley - part 1, part 2, part 3

Xslt and Macro’s:

XSLT Basics
Inline xslt (new in v4)
Macro Parameters syntax

Canvas:

Introduction to Canvas

Beyond the Basics:

.Net controls and umbraco:

Screencast 1
Screencast 2

Event model:

Attaching document eventhandlers
Using ApplicationBase to register events

Base:

Introduction to /Base

Xslt extension:

Create xslt exstension like umbraco.Library

Custom datatypes:

Creating custom datatypes using the umbraco usercontrol wrapper
Creating custom umbraco datatypes

Getting started with umbraco 10

Last Saturday, during the umbraco meetup the ‘lack of documentation’ topic came up ( as usual ). So for al those people trying to get started….

A great way to get started is to install Warren’s creative web site wizard and to take a look at how things are set up and how it interconnects (developer section, right click macro’s, choose import package then open the repository and install the package). You can also find different references on the web, I tried to structure some of them in this ‘getting started’ list.

Download:

You can always find the latest release on codeplex (currently 3.0.5)
http://www.codeplex.com/umbraco/Release/ProjectReleases.aspx?ReleaseId=6344

Installation:
http://www.umbraco.org/v4 (link to screencast in the bottom right of the page)
http://umbraco.org/documentation/books/install-umbraco-21x-on-windows-xp
http://umbraco.org/documentation/books/install-umbraco-30-on-windows-server-2003
http://umbraco.org/documentation/books/install-umbraco-30-on-windows-vista
http://umbraco.org/documentation/books/install-umbraco-30-on-windows-xp

Basics:
Document Types:
http://www.umbraco.org/blog/2007/12/3/dec-3-umbraco-basics-document-types
http://www.umbraco.org/blog/2007/12/6/dec-6-document-types-part-ii
http://www.umbraco.org/documentation/books/document-types-explained

Templates:
http://www.umbraco.org/blog/2007/12/7/dec-7-templates-part-i—the-introduction
http://www.umbraco.org/blog/2007/12/12/dec-8-adding-page-information-to-templates
http://www.umbraco.org/blog/2007/12/13/dec-9-using-master-templates
http://www.umbraco.org/documentation/books/templates-explained

Xslt and Macro’s:
http://umbraco.org/documentation/books/xslt-basics
http://umbraco.org/documentation/books/extending-xslt-with-c-or-javascript
http://umbraco.org/documentation/books/macro-parameters-syntax

Beyond the Basics:
.Net controls and umbraco:
http://en.wikibooks.org/wiki/Umbraco/Samples_and_Articles/Dot_Net_Controls
http://www.nibble.be/?p=12

Actionhandler:
http://www.umbraco.org/documentation/books/creating-and-using-an-action-handler

Base:
http://www.umbraco.org/documentation/books/introduction-to-base

Xslt extension:
http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C

Custom datatypes:
http://www.nibble.be/?p=24

Flash and umbraco:
http://www.nibble.be/?p=28

 

Still having trouble to get started ? The umbraco community is great, so sign up to the umbraco forum and post your questions.

Hello umbraco world 2

Indeed a new blog about umbraco, planning on filling this with tips,tricks, examples and screencasts ( like I did with the http://tim.netcentric.be blog but I will try to have more detailed and richer posts )