0 votes

Umbraco Utilities

Umbraco Utilities

Very useful library which consists of two main namespaces

  • Excetnsions
  • Configuration
Extensions namespace

This namespace contains extensions for IPublishedContent and IContent along with some useful extensions for HttpRequest and other .NET Framework classes to make work easier.

Configuration namespace

There is only one static class in this namespace named Config which enables reading quick config file. This file is stored in /Config/Website.config location.

This enables adding of some config values without touching Web.config and restarting app on IIS.
Fetching values from file is really easy and it is based on simplified XPath.
The following is example how to read sample config file in Razor template.

<?xml version="1.0"?>

<config>

  <projectname>Umbraco utilities</projectname>

  <projectmajorver>1</projectmajorver>

  <projectactive>true</projectactive>

  <mobiledevices>

    <device>Nokia X</device>

    <device>Sony Xperia</device>

    <device>iPhone5</device>

  </mobiledevices>

</config>


The following is sample razor template which shows hot read above shown sample Website.config.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@using Umbraco.Utils.Configuration

@using Umbraco.Utils.Extensions

@{

    Layout = null;

}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <title>@Model.Content.GetPropertyValueAsString("title")</title>

  </head>

  <body>

      <h1>@Model.Content.GetPropertyValueAsString("title")</h1>

      <p>

          String value: @Config.GetValueAsString("/config/projectname")

      </p>

      <p>

          Integer value: @Config.GetValueAsString("/config/projectmajorver")

      </p>

      <p>

          Boolean value: @Config.GetValueAsString("/config/projectactive")

      </p>

      <p>

          List value:

          <ul>

              @foreach (string listValue in Config.GetValueAsStringList("/config/mobiledevices/device"))

              {

                  <li>@listValue</li>

              }

          </ul>

      </p>

  </body>

</html>

Screenshots

Package owner

Dejan Stojanovic

Dejan Stojanovic

Dejan has 51 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions:

Package Information

  • Package owner: Dejan Stojanovic
  • Created: 26/05/2014
  • Current version 1.0
  • License MIT
  • Downloads on Our: 810