Author Archives: Alf

Slight update on the Tool for Page Type Classes from Page Types in EPiServer 7 CMS

I made a small mistake on the Page Type Class Tool for EPiServer 7 CMS. This was on the SetDefaultValues method where the ChildOrderRule was set to FilterSortOrder.None.

If a Page have a ChildOrderRule set to None, EPiServer won’t be able to find the Children of that Page since the Stored Procedure does not know how to handle that ChildOrderRule.

Therefore I have added a check whether pageType.Defaults.ChildOrderRule is not FilterSortOrder.None before setting the value.

Some information behind the scenes

FilterSortOrder.None is basically a value that means that there is no specific default value setting for this Page Type stored in tblPropertyDefinitionDefault.

If the ChildOrderRule is set to None, the default values provided by PageDataBuilder.SetPropertyValues() will be set, which means that the default value is 1 (CreatedDescending).

Even the class PageData where SetDefaultValues() is defined have a check for ChildOrderRule.

if (pageType.Defaults.ChildOrderRule != FilterSortOrder.None)
    property["PageChildOrderRule"].Value = (object) pageType.Defaults.ChildOrderRule;

What should I do if I have used the faulty version?

All you need to do is to remove the following row from all your Page Type Classes:

this[MetaDataProperties.PageChildOrderRule] = FilterSortOrder.None;

And run following in your database to fix all pages that have already been created with wrong ChildOrderRule:

UPDATE [tblContent] SET ChildOrderRule = 1 WHERE ChildOrderRule = -1

I am sorry for the inconvenience, if you find more bugs or have suggestions on how to improve, please tell me.

Find Pages containing a certain Content in a ContentArea (UPDATE)

good-news-everyone

I had some discussions about this blog post and had to check up some things. Accidently I found the IContentRepository.GetReferenceInformationForContent(ContentReference contentLink, bool includeDecendents) (implemented on DataFactory) which runs the Stored Procedure [editDeletePageCheck]. This is normally used to warn an editor about referencing pages when editing och deleting content.

According to the ExpressProfiler it goes to the database each time I run the command so it might be good to keep this in mind.

Here is the new code:

var contents = new List<ContentData>();
var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
IEnumerable references = repository.GetReferencesToContent(contentLink, false);
foreach (ReferenceInformation reference in references)
{
    ContentReference ownerContentLink = reference.OwnerID;
    CultureInfo ownerLanguage = reference.OwnerLanguage;
    ILanguageSelector selector = new LanguageSelector(ownerLanguage.Name);
    var content = repository.Get<ContentData>(ownerContentLink, selector);

    var contentArea = content["ResponsibleEditors"] as ContentArea;
    if (contentArea != null)
    {
        if (contentArea.ContentFragments.Any(fragment => fragment.ContentLink == contentLink))
            contents.Add(content);
    }
}

While browsing in the tblContentProperty I stumbled upon how a ContentArea is saved in the database.

It’s quite similar to how Dynamic Content is serialized in a XhtmlString:

<div data-classid=”36f4349b-8093-492b-b616-05d8964e4c89″ data-contentguid=”7cef1c69-b345-493c-a60e-ce011fe42c31″ data-contentlink=”35″ data-contentname=”Content Name”>{}</div><div data-classid=”36f4349b-8093-492b-b616-05d8964e4c89″ data-contentguid=”216210e0-f687-4f7a-9bc9-c2a51badab1a” data-contentlink=”701″ data-contentname=”Another Content Name”>{}</div>

In my example I have a Page Type called EditorPage presenting all persons in the staff who can be responsible to the web sites articles.

To present an articles responsible editor I have added a ContentArea where the editor simply drops Editor Pages.

On the Editor Page I want to list all the article where the Editor is connected.

So all I have to do to find pages that have a specific Content (for example Page or Block) referenced in a ContentArea is this:

string id = ID-TO-YOUR-CONTENT;
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection
{
    new PropertyCriteria
        {
            Condition = CompareCondition.Contained,
            Name = "ResponsibleEditors",
            Required = true,
            Type = PropertyDataType.String,
            Value = string.Format("data-contentlink=\"{0}\"", id)
        }
};
IPageCriteriaQueryService queryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();
PageDataCollection pages = queryService.FindPagesWithCriteria(ContentReference.StartPage, criterias);

You can also use the content GUID and use this as Value: string.Format(“data-contentguid=\”{0}\””, guid)

As usual, if you want to use FindPagesWithCriteria, remember to put a cache on it since it can be quite heavy on the database.

The quest of FindPagesWithCriteria with a Block Property in EPiServer 7 CMS

There are several exciting things with the new Blocks in EPiServer 7 CMS. One of the most convenient things when you need to add a group of data to a page type, for example an image + alternative text or an url + clickable text or maybe a group of SEO data such as title, description and keywords.

Note that this article does not include how Global Blocks are saved. I have only focused on Blocks that are added as Properties on a Content Type.

I have create a sample Page Type TestPage containing 2 sets of the block TestBlock which itself only contains the string Property TestValue. TestBlock1 contains the value “abc” and TestBlock2 contains the value “def”.

When I check the database structure I can find these traces of ContentTypes, Properties and values. I have marked the recurring values to mark how the relations are set between all  tables.

Database Structure

[tblContentType]

pkID ContentTypeGUID ModelType Name ContentType
23 34CC512A-5680-47CA-86EF-80F38A688F40 EPiServer.Templates.Alloy.Models.Blocks.TestBlock, EPiServer.Templates.Alloy, Version=1.0.0.30998, Culture=neutral, PublicKeyToken=null TestBlock 1
24 64E21501-096A-4983-AE87-03D274FE98B2 EPiServer.Templates.Alloy.Models.Pages.TestPage, EPiServer.Templates.Alloy, Version=1.0.0.30998, Culture=neutral, PublicKeyToken=null TestPage 0

[tblPropertyDefinitionType]

pkID Property Name TypeName AssemblyName fkContentTypeGUID
1010 12 TestBlock NULL NULL 34CC512A-5680-47CA-86EF-80F38A688F40

Where the column fkContentTypeGUID is null on PropertyDefinitionTypes that are not connected to a ContentType

[tblPropertyDefinition]

pkID fkContentTypeID fkPropertyDefinitionTypeID Name Property
133 23 7 TestValue 7
134 24 1010 TestBlock1 12
135 24 1010 TestBlock2 12

Where fkPropertyDefinitionTypeID 7 mean it’s a normal string and strangely 12 is a XhtmlString but I guess it has something to do with rendering. *adding to future blogs list*

[tblContentProperty]

pkID fkPropertyDefinitionID fkContentID fkLanguageBranchID ScopeName guid LongString LongStringLength
1628 133 183 1 .134.133. 1C2D6A8D-6973-4E36-9BC9-9E655506795C abc 6
1628 133 183 1 .135.133. 1C2D6A8D-6973-4E36-9BC9-9E655506795C def 6

I have created a Page of TestPage. The page have Id 183, it didn’t feel necessary to add that table to this chart but as you can see, the values of TestBlock1 and TestBlock2 have a fkContentID that referers to the PageData it is stored on.

The column ScopeName is a relational path that connects the Name property to the TestBlock Block named TestBlock1.

Find Pages based on this?

The datastructure for Blocks in tblContrentProperty are quite flat. Therefore I can find my Test Page by creating a FindPagesWithCriteria:

IPageCriteriaQueryService repository = ServiceLocator.Current.GetInstance();

PropertyCriteriaCollection criterias = new PropertyCriteriaCollection
{
    new PropertyCriteria
    {
        Condition = CompareCondition.Equal,
        Required = true,
        Name = "TestValue",
        Type = PropertyDataType.String,
        Value = "abc"
    }
};
PageDataCollection result = repository.FindPagesWithCriteria(ContentReference.RootPage, criterias);

FindPagesWithCriteria sends queries to a couple of Stored Procedures in the database and checks among the tables whether the Pages have a Property with the given name and  if the Property value fits the criteria.

And what is the result?

Unfortunately since there is no way to define that I only want to search for a page where TestBlock1 have a TestValue with value “abc”, I will receive ALL pages that have a Property called TestValue with a value of “abc” no matter if they are saved on a block or directly on the page.

This really sounds like a job for EPiServer Find but if you don’t have it installed, FindPagesWithCriteria can be quite good at times except for the disadvantages of many queries to the database and its cumbersome API.

Though the advantages is its stability and being straightforward. Remember to not add too many criterion and try to Cache-smart if you using it

What I can find there is no good way to change the behaviour of FindPagesWithCriteria without copying quite alot of the existing logic or rewriting the existing Stores Procedures.

Resolve PageType & ContentType from Class

In PageTypeBuilder for EPiServer CMS 6 we had a lovely feature called PageTypeResolver which could be used to find the Id of a PageType based on your implementation of TypedPageData. All you needed to do is run PageTypeResolver.Instance.GetPageTypeID(typeof(MyPageType)) and you would get a Nullable Int which represents the Id of your PageType, or null if no PageType could be found. In EPiServer 7 CMS this has been built into the main functionality of Page Types / Content Types and all you need to do is this:

  • Find the implementation of IContentTypeRepository you’re looking for:
    var repository = ServiceLocator.Current.GetInstance<IContentTypeRepository<PageType>>();
    var repository = ServiceLocator.Current.GetInstance<IContentTypeRepository<BlockTypeType>>();
    var repository = ServiceLocator.Current.GetInstance<PageTypeRepository>();
    var repository = ServiceLocator.Current.GetInstance<BlockTypeRepository>();
  • Load the page type based on your implementation of BlockData/PageData:
    var contentType = repository.Load(typeof(MyPageType));

If you’re locating the PageTypeRepository or BlockTypeRepository implementations directly you can also find the shortcut:

var contentType = repository.Load<MyPageType>();

If you try to load an instance of ContentData that does not exist, Load() will return null.

Simplifying event handling in EPiServer 7 CMS

While adding some Blocks to a project I was thinking of a concept that I’ve had in mind for a while. Some way to make it easier to hook your logic to EPiServer events such as creating pages, publishing pages.

The project can be downloaded from my repository on GitHub. I hope this will make your event handling in EPiServer much easier!

My example is a block that represents a header to group blocks.

[ContentType(DisplayName = "Column Heading", Description = "A heading in the column", GUID = "0A9BEC10-5795-43D5-B305-130ED6222D8A")]
public class ColumnHeadingBlock : BlockData
{
  [Display(GroupName = SystemTabNames.Content, Order = 1)]
  public virtual string Heading { get; set; }
}

Since it only has one property, it would be nice that it would be populated with the name given when the Block was created.

column heading

First approach: override SetDefaultValues

I noticed that the instance of my ColumnHeadingBlock is a ColumnHeadingBlockProxy that seems to be created  by EPiServer.Construction.SharedBlockFactory.CreateSharedBlock and that the proxy also is implementing the IContent Interface. Hence I can Cast my to IContent and retrieve the IContent.Name implementation.

Sadly SetDefaultValues are run before the Name is set and returns null.

Second approach: EPiServer.DataFactory.CreatingContent Event

This seems to do the trick. CreatingContent is triggered after SetDefaultValues and contentEventArgs.Content.Name returns the name I gave when creating the Block.

Wrapping things up: Initialization and reusability

The idea that have been growing inside my head is that I shouldn’t need to clutter global.asax or create InitializationModules everytime I want something to happen when I create, save, publish, move a page.

Therefore I created my EventHelper where I only need to implement an Interface to my Page Type Class where I add the logic to be run under certain Events. This could be re-registering Routes, notifying people, logging things etc when something is done in EPiServer.

In my example where I want to set a value to a Block Property when it is created, the implementation would look like this:

[ContentType(DisplayName = "Column Heading", Description = "A heading in the column", GUID = "0A9BEC10-5795-43D5-B305-130ED6222D8A")]
public class ColumnHeadingBlock : BlockData, ICreatingContent
{
  [Display(GroupName = SystemTabNames.Content, Order = 1)]
  public virtual string Heading { get; set; }

  public void CreatingContent(object sender, ContentEventArgs contentEventArgs)
  {
    Heading = contentEventArgs.Content.Name;
  }
}

Behind the scenes

The project contains an InitializationModule where I hookup basically all Events I could find in the DataFactory. I excluded the LoadingChildren Events since I don’t really know what the best implementation of this could be. Maybe something for a later version?

The CreatingContent Event is hooked up to the method DataFactoryEvents.CreatingContent.

DataFactory.Instance.CreatingContent += DataFactoryEvents.CreatingContent;

The DataFactoryEvents.CreatingContent method looks like this:

public static void CreatingContent(object sender, ContentEventArgs e)
{
  var content = e.Content as ICreatingContent;
  if (content == null)
    return;
  content.CreatingContent(sender, e);
}

Here is a list of the other Events I’m using – as you can see I’ve also implemented Page Events as well as the Content Events.

I have not yet given myself time to see if it’s necessary to be able to implement both Content and Page, but since the Page Event is not obsolete I guess both would be good.

  • CheckedInContent
  • CheckedInPage
  • CheckingInContent
  • CheckingInPage
  • CreatedContent
  • CreatedPage
  • CreatingContent
  • CreatingPage
  • DeletedContent
  • DeletedContentLanguage
  • DeletedContentVersion
  • DeletedPage
  • DeletedPageLanguage
  • DeletingContent
  • DeletingContentLanguage
  • DeletingContentVersion
  • DeletingPage
  • DeletingPageLanguage
  • FailedLoadingContent
  • FailedLoadingPage
  • FinishedLoadingPage
  • LoadedContent
  • LoadedDefaultContent
  • LoadedDefaultPageData
  • LoadedPage
  • LoadingContent
  • LoadingDefaultContent
  • LoadingDefaultPageData
  • LoadingPage
  • MovedContent
  • MovedPage
  • MovingContent
  • MovingPage
  • PublishedContent
  • PublishedPage
  • PublishingContent
  • PublishingPage
  • SavedContent
  • SavedPage
  • SavingContent
  • SavingPage
Tagged

Creating Page Type Classes from Page Types in EPiServer CMS 7

After my upgrade of Stockholm Pride to EPiServer 7 CMS (blog post coming soon) I wanted the project to be a bit more shiny with some Code Managed Page Types.

I forked Erik Nordin’s utility to create classes for PageTypeBuilder in an existing project. Did some research on what attributes I needed to create a similar thing with EPiServer 7 CMS.

As a bonus I also gave it a little more EPiServer look-and-feel:

create pt

Since I don’t know if I should commit this back to Erik Nordin’s GitHub or not, you can download it from GitHub.

Current status

I would see this as a first draft of the creation tool that worked quite good for my upgrade of Stockholm Pride.

It creates Properties for the most common properties in EPiServer but gives a template where you can decide if you want to go with a BackingTypeAttribute or using EditorDescriptors/UIHints instead (see below).

Attributes and value types

I’ve tried to cover all correct DataTypes Attributes such as replacing PropertyImageUrl with Url and setting UIHints but I still thinks it needs some more cleaning.

Note that since I only check for what’s in the database, avoid running this tool while already having Page Types Classes in your project.

Custom Properties

For now, the support for Custom Properties are not that great. I try to read out what kind of Data Value the Properties are meant to return but leave a code comment to those Properties I don’t know what to do with.

This way you can make a search for //DefinitionType= and decide for yourself if you want to use the UIHintAttribute or the BackingFieldAttribute to solve this problem.

Some of the older EPiServer Properties are obsolete which mean that they should not be used as a BackingField.

UILanguageProperty is one of them which luckily is only a property that returns a string, but the Editor may select among all activated Languages.

By reflection I can find out exactly how that list is populated.

Example of EditorDescriptor

This means that UILanguageProperty can easily be replaced with an EditorDescriptor that gives the same functionality:

//DefinitionType=EPiServer.SpecializedProperties.PropertyUILanguage
//[BackingType(typeof(PropertyUILanguage))] -- PropertyUILanguage has been obsoleted and will be removed in a future release.
[UIHint("UILanguage")]
[Display(Name = "Content Language")]
public virtual string ContentLanguage { get; set; }

[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = "UILanguage")]
public class UILanguageEditorDescriptor : EditorDescriptor
{
   public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
   {
      SelectionFactoryType = typeof(UILanguageSelectionFactory);
      ClientEditingClass = "epi.cms.contentediting.editors.SelectionEditor";

      base.ModifyMetadata(metadata, attributes);
   }
}

public class UILanguageSelectionFactory : ISelectionFactory
{
   public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
   {
      var languages = new List<SelectItem>();
      foreach (System.Globalization.CultureInfo info in LocalizationService.Current.AvailableLocalizations)
      {
         string nativeName = info.NativeName;
         if (info.TextInfo.ANSICodePage != 0x4e4)
         {
            nativeName = nativeName + string.Format(" ({0})", info.EnglishName);
         }
         languages.Add(new SelectItem { Value = info.Name, Text = nativeName });
      }
      return languages;
   }
}

NullReferenceException from TinyMCESettings, InputTinyOptions.GetActiveToolsHTML() and ToolbarRow in EPiServer 7

I’m upgrading a quite old EPiServer CMS website that has been alive since about 2007 from EPiServer CMS 6 to EPiServer 7 CMS.

Among the first things after using EPiServer Deployment Center to upgrade from CMS 6 R2 to 7 CMS is that I can’t use the new shiny Editor Mode.

Not being able to edit First Page

It looks good but no reaction when I click to edit a property or trying to enter Forms Editing.

A quick look in my browser’s Developer Network  gives me a HTTP Error 500 from the following url:
/secure/shell/Stores/metadata/?type=EPiServer.Core.ContentData&modelAccessor=%7B”contentLink”%3A”3_35644″%7D&dojo.preventCache=1362601343237

secure-shell-stores-metadata

I also had some strange errors when trying to edit TinyMCE Property Settings:

edit xhtmlstring settings

After some Reflecting, Debugging and some hints from http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=64169 I found that in the upgrade from 6R2 to 7, the Upgrade Tool moves some DDS-items such as Property Configuration from tblBigTable to tblSystemBigTable.

But the View VW_EPiServer.Editor.TinyMCE.ToolbarRow nor the Stored Procedure Save_EPiServer.Editor.TinyMCE.ToolbarRow are not updated to load or save from the correct Big Table causing the DDS to be able to find the TinyMCESettings correctly but when the nested entities ToolbarRow are loaded, no such data is found. Hence TinyMCESettings.Toolbar returns a list but all items in the list are NULL.

The correct procedure seems to be to change the design of the View to

SELECT CAST(R01.pkId AS varchar(50)) + ':' + UPPER(CAST([Identity].Guid AS varchar(50))) AS Id, R01.pkId AS StoreId, [Identity].Guid AS ExternalId, R01.ItemType
FROM dbo.tblSystemBigTable AS R01 INNER JOIN
 dbo.tblBigTableIdentity AS [Identity] ON R01.pkId = [Identity].pkId
WHERE (R01.StoreName = 'EPiServer.Editor.TinyMCE.ToolbarRow') AND (R01.Row = 1)

and the Stored Procedure to

USE [dbStockholmPrideDev_EPi7]
GO
/****** Object: StoredProcedure [dbo].[Save_EPiServer.Editor.TinyMCE.ToolbarRow] Script Date: 03/04/2013 09:45:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Save_EPiServer.Editor.TinyMCE.ToolbarRow]
@Id bigint output,
@UniqueId uniqueidentifier,
@ItemType nvarchar(2048)
as
begin
declare @pkId bigint
 select @pkId = pkId from tblBigTableIdentity where [Guid] = @UniqueId
 if @pkId IS NULL
 begin
 begin transaction
 insert into [tblBigTableIdentity]([Guid], [StoreName]) values(@UniqueId, 'EPiServer.Editor.TinyMCE.ToolbarRow')
select @Id = SCOPE_IDENTITY()
 insert into [tblSystemBigTable] (pkId, StoreName, Row, ItemType)
 values(@Id, 'EPiServer.Editor.TinyMCE.ToolbarRow', 1, @ItemType )
commit transaction
 end
 else
 begin
 begin transaction
 select @Id = @pkId
 DECLARE @rows int
 select @rows = count(*) from [tblSystemBigTable] where pkId = @Id
 if(@rows < 1) begin
 insert into [tblSystemBigTable] (pkId, StoreName, Row, ItemType)
 values(@Id, 'EPiServer.Editor.TinyMCE.ToolbarRow', 1, @ItemType )
end
 commit transaction
 end
end

EPiServer DDS + Enum

We found a problem when having Nullable Enum values in our DDS objects. We got an error “Invalid cast from ‘System.Int32’ to ‘RoleData.MyEnum’.” when we tried to iterate through our repository.

Others seem to have the same problem as well.

According to Paul Smith there seems to be some problems, I didn’t get the e-mail response myself so I must get back with more details.

This is my solution, using a TypeHandler, had totally forgotten about that part in the DDS Example Package.

    public class EnumTypeHandler : ITypeHandler
    {
        //From int to enum
        public object FromDatabaseFormat(string propertyName,
                                         object propertyValue,
                                         Type targetType, Type ownerType)
        {
            if (propertyValue == null)
                return null;

            Type valueType = targetType;
            if (IsNullable(targetType))
            {
                valueType = Nullable.GetUnderlyingType(targetType);
            }
            if (valueType.IsEnum)
            {
                string stringValue = Convert.ToString(propertyValue);
                return Enum.Parse(valueType, propertyValue.ToString());
            }
            return propertyValue;
        }

        //returns int type
        public Type MapToDatabaseType(Type type)
        {
            if (type.IsEnum)
            {
                if(IsNullable(type))
                    return typeof(int?);
                return typeof(int);
            }
            return type;
        }

        //convert enum to int
        public object ToDatabaseFormat(string propertyName,
                                       object propertyValue,
                                       Type ownerType)
        {
            if (propertyValue == null)
                return null;
            if (propertyValue is Enum)
                return Convert.ToInt32(propertyValue);
            return propertyValue;
        }

        private bool IsNullable(Type type)
        {
            return (type.IsGenericType && type.GetGenericTypeDefinition()
                                              .Equals(typeof(Nullable<>)));
        }
    }

It only takes care of int Enums at the moment but it’ll do.

And in EPiServer FirstBeginRequest I added the Handler by adding:

if (!GlobalTypeHandlers.Instance.ContainsKey(enumType))
    GlobalTypeHandlers.Instance.Add(enumType, new EnumTypeHandler());

Where enumType is each Enum I need to handle in my DDS object.

Using PropertyDropDownList with EPiServer Dynamic Content

I’m creating a “widget” where the client is supposed to be able to change color to a Teaser. The color options should be editable quite easily.

The widget is added to the page by using Dynamic Content.
So I’m using the PropertyDropDownList added in EPiServer CMS 6 R2 so an administrator can edit the options through the Administrator Mode (or when PagetTypeBuilder 2 comes, a developer by creating a class deriving from IUpdateGlobalPropertySettings<MultipleOptionsListSettings>).

But since all ways to change the Property’s Settings values are locked from external binaries, I couldn’t find any other way to connect my Global Setting to the DropDownList in my Dynamic Content except creating a Custom Property that derives from PropertyDropDownList.

After that I create a Global Setting for DropDownList with some colors which I set as default for my PropertyTeaserColorDropDownList.

So by adding a Property of type PropertyTeaserColorDropDownList in my Dynamic Content class, I can let my Editor select a color from a list managed by the Administrator.

Code examples

public class PropertyTeaserColorDropDownList : PropertyDropDownList
{
}

[DynamicContentPlugIn(DisplayName = "Front Teaser", ViewUrl = "~/Widgets/FrontTeaserWidget/FrontTeaserWidget.ascx")]
public partial class FrontTeaserWidgetControl : WidgetControlBase
{
    public PropertyTeaserColorDropDownList TeaserColor { get; set; }
}

It feels a bit cumbersome to create a Custom Property for this. It would be nice if I could set the SettingsId somehow or if it could be set by some attribute.

Summary of resize image in EPiServer Template Foundation

I’m working on my first ETF project, and sadly I’m not that overwhelmed but that’s another story.

This story is about using the resize image function, I didn’t find a good blog post on how to use this, except how to activate the functionality:

I didn’t setup this project but as you can read on Ted’s blog about Creating a new website using Template Foundation you’re supposed to add the following to web.config:

<configuration>
<configSections>
<section name=”DynamicImageProcessor” type=”TemplateFoundation.Handlers.DynamicImageProcessor.ProcessorConfig” />
</configSections>
<DynamicImageProcessor>
<Cache CacheDirectory=”C:\Temp\dynamicimageprocessor-test” Enabled=”true” />
</DynamicImageProcessor>
</configuration>

You’re also supposed to add these handlers on the paths you want to activate:

<add name=”png” verb=”GET,HEAD” path=”*.png” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />
<add name=”jpg” verb=”GET,HEAD” path=”*.jpg” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />
<add name=”gif” verb=”GET,HEAD” path=”*.gif” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />

In my example I want to be able to modify images uploaded to the PageFiles directory, Therefore my configuration will look like this;

<location path=”PageFiles”>
<system.webServer>
<handlers>
<add name=”webresources” path=”WebResource.axd” verb=”GET” type=”System.Web.Handlers.AssemblyResourceLoader” />
<!– Dynamic Image Processor –>
<add name=”png” verb=”GET,HEAD” path=”*.png” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />
<add name=”jpg” verb=”GET,HEAD” path=”*.jpg” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />
<add name=”gif” verb=”GET,HEAD” path=”*.gif” type=”TemplateFoundation.Handlers.DynamicImageProcessor.Processor” />
<!– End of Dynamic Image Processor–>
<add name=”wildcard” path=”*” verb=”*” type=”EPiServer.Web.StaticFileHandler, EPiServer” />
</handlers>
</system.webServer>
<staticFile expirationTime=”-1.0:0:0″ />
</location>

I know that already, how do I use this?

To fetch a resized image, all I need to do is to browse to the file and add some parameters:

http://myproject/PageFiles/4474/328.jpg?w=107&ch=76

This combination of w and ch means that the size will be shrunk to 107 px width, but cropped to 76 px height.

Other parameters you can add are:

integers:
w: resized width, the image will be resized to fit this width (can be replaced with “width”)
h: resized height, the image will be resized to fit this height (can be replaced with “height”)
cw: cropped width, the image will be cropped to fit this width
ch: cropped height, the image will be cropped to fit this height
ox: offset x position on cropping, default is center of image
oy: offset y position on cropping, default is center of image

booleans:
r: keep aspect ratio
up: the image may be resized to larger than original image

I hope this post gave you some help on how to change the sizes in a Template Foundation web site.

/Alf

:<section name="DynamicImageProcessor" type="TemplateFoundation.Handlers.DynamicImageProcessor.ProcessorConfig" /