Umbraco Codegarden ‘08, Umbraco hints and tips
Having only used Umbraco for a couple of weeks, it was great to have the opportunity to attend the Codegarden event. This was an opportunity to meet other developers and to learn about Umbraco.
It was also an opportunity to pick up some helpful hints and tips, which I’ve documented in this post.
Since I am barely a .NET developer (I have taught myself .NET in around 3 days !) I was quite apprehensive about how much I would understand. Fortunately, there were 2 different streams – intermediate and advanced.
I attended the intermediate streams on Day 1 and found that they were generally very good, although (surprisingly!) they were aimed at real beginners: I’d been using Umbraco for a couple of weeks and some of the subjects (XSLT for example) I had already experienced at home.
That said, for those who had not yet felt some of that pain, I am sure it was a welcome introduction!
The announcement of Umbraco v4 was extremely welcome. It looks as though the v4 enhancements will not only be welcome, but will make Umbraco a more serious tool.
In particular, the ability to roll between environments is a “must have” and I can’t wait for that functionality to be released!
Hints and Tips
While at Code Garden I captured some helpful hints and tips which I’ve documented below.
Control your URLs
It is possible to override the default url generated by Umbraco (based on the document Name). To do this, you must add a field named “umbracoUrlName” (of data type “Textstring” to your Document Type).
When entering/editing content, the value entered for “umbracoUrlName” will be used to create the filename portion of the URL (”filename.aspx”).
Multiple URLs for the same document
If you add a field named “umbracoUrlAlias” to the Document Type, this can be used to specify alternative URLs for a document. Again, this field should have the “Textstring” datatype. Multiple aliases can be specified – they can be comma-separated.
Tokens in Templates
Umbraco allows you to specify tokens when passing information to Macros within templates. Tokens are then replaced at runtime with suitable content.
Tokens are placed inside square brackets [...]. The tokens which were discussed were:
- [#pageID]
This token will be replaced with the ID of the current page. - [#key]
Pull the dictionary item with the specified key - [@name]
return the value of Request(name); for example, from either the query string or from a POST request - [%name]
return a value from Session. Session information can be set using XSLT if required, using the umbraco library functions. For example,<xsl:variable name="sessionVar" select="umbraco.library.setSession('name','value')" /> - [$recursive]
returns the value of a field named “recursive”. If this field is not found, or is empty, Umbraco will search for a parent document which has a field named “recursive” which is not empty. I cannot get this to work so have struck this from the post.
Recursive Fields
When inserting a field into a template, the dialog has a “Recursive” check box. If this is ticked, the [$recursive] functionality described above is activated: If this field is not found, or is empty, Umbraco will search for a parent document which has a field named “recursive” which is not empty.
Struggling with XSLT? Take a peek at the Umbraco XML file
You can view the XML which is parsed by the XSLT processor. Simply locate the “data/umbraco.config” file on the Umbraco IIS server. This can be used to develop and even debug XSLT in Visual Studio.
umbracoNaviHide
Many XSLT functions and templates refer to a document property called “umbracoNaviHide”. If you include this property (as a true/false data type) in your documents, you can hide the document/content node from XSLT queries which adhere to this convention.
Multiple Domains
You can have multiple domains point to the same Umbraco site. Right-Click on the site root node, choose Copy, and tick the “Relate” check box. The copied site can then be associated with a different domain name. Updates to the copy/original site will be mirrored in the original/copied site.
Multilingual Sites
Insert an Umbraco field into a template. The name of the field should begin with the ‘#’ character. The rest of the field name will be treated as a dictionary key, and the dictionary value will be used in place of the field.
Scheduled Tasks
Scheduled tasks can be configured by editing the web.config file. This will cause a particular aspx page to be executed at a regular interval.
Insert Images without using XSLT
It is possible to insert images without using XSLT! Unfortunately, my notes on this one turned out to be innaccurate. So I asked the guys on the Umbraco forum for help and this is what they came up with:
<img src='<umbraco:Item field="umbracoFile" nodeid="1072" runat="server"></umbraco:Item>' />
It should also be possible to use “insertTextBefore” and “insertTextAfter”, however this is not currently working on my copy of Umbraco v4. The modified syntax would then be:
<umbraco:Item field="umbracoFile" nodeid="1072"
insertTextBefore="<img src='"
insertTextAfter="' />"
runat="server"></umbraco:Item>