Non embedded tiles
tiles outside the assembly
The previous examples all have the tiles embedded in the assembly. This is the default configuration of SharpTiles. However this might not be desired. SharpTiles allows for changing the way resources are found. Resources are found through resource locators this can be configured. SharpTiles comes with three build in factories:
- AssemblyBasedResourceLocator - Assembly based
- FileLocator - File based
- VirtualDirLocator - File based prepared for web use
In the custom tile repository example we will show how to build your own resource locator.
This tutorial change the previous tutorial to use the VirtualDirLocator. To accomplish this we need to make changes in the web.config. We need to add a tilesConfiguration.
Web.config
...
</sectionGroup>
<section name="tilesConfiguration"
type="org.SharpTiles.Connectors.TilesConfigurationSection,
org.SharpTiles"/>1
</configSections>
<appSettings/>
<tilesConfiguration ConfigFilePath="my.tiles.xml"
RefreshIntervalSeconds="15"
FilePrefix="Views/"
ResourceFactory="org.SharpTiles.Connectors.VirtualDirLocatorFactory,
org.SharpTiles,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null"/>2
<connectionStrings>
...
- Defines the config section. This is standard for adding a config section in .NET
- With the ResourceFactory SharpTiles is configured to use the web virtual directory locator. This is basicly the file locator using the webvirtual dir as a starting point. The 'Prefix' adds an additional prefix before the requested resource. In this case the views folder is also prepended. So Home/Index.tile becomes <virtual dir>/View/Home/Index.tile. The 'RefreshIntervalSeconds' specifies how often SharpTiles checks if any of the resources are changed.
Make sure that all tiles, .tile, and tiles.xml are marked as Content instead of Embedded Resource. We also need to change the tiles.xml file. File paths uses '/' instead of an '.' see the *
<?xml version="1.0" encoding="utf-16"?>
<tiles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<definitions>
...
<tile name="Home.Index" extends="Default.Page.Layout">
<attribute name="title" type="String" value="Home Page"/>
<attribute name="body" value="Views/*Home.Index.tile"/>
</tile>
...
</definitions>
</tiles>