Managing resources

Resources are snippets of content reused across a Web site. Manage these bits of text as custom resources that you can edited and translate in the Content Manager.

About this task

An example of a resource is the More Info button text written on the Special Offer View. The example view has hard coded text which means you cannot use it in a multi-language context or be edited by non-technical people. The recommended approach is to manage resources as content in special resource Components. The Component can use the General Configuration Schema, or you can create a custom Schema:
Advantages of Custom Schema
The main advantage of using a custom Schema are: Users cannot edit the configuration 'key' - its the XML field name of the field in the schema, only the 'value', which is simply the field value. You ensure key uniqueness within your component, as you cannot have 2 fields with the same XML name When you add a new config setting (field in the schema), it is available for editing in all localizations of the resource component (although will be empty) You have some control over the data type used for the configuration field (in theory you could use date/number/categories for the resource values as well as plain text, although the web application Config method will always return a string)
Advantages of General Configuration Schema
The main advantages of using the General Configuration schema are: Creating a component based on an existing schema is more straightforward than creating a new schema You do not have schema bloat - having lots of configuration schemas can lead to confusion when creating new content

Procedure

  1. Create a new resource Component:
    1. Go to the Folder where you want to create the Component.

      It is recommended to create the Folder in Building Blocks/Settings/ModuleName/Role Folder, where ModuleName is the name of your Module, and Role is one of Developer, Site Manager or Editor, enabling you to set up role-based security on who is allowed to edit the resources and other module settings. For example, Building Blocks/Settings/MyCompanyExamples/SiteManager.

    2. Create a new resource Component called Special Offer Resources using the General Configuration Schema (multi-value name/value pairs).
    3. Add a new value:
      • set Name to moreInfoText
      • set Value to More Info
    4. Link the Component to the main Module configuration Component in the Resources field.
      If you do not have one of these already, create a Component using the Module Configuration Schema in: Building Blocks/Modules/ModuleName/Admin and give it the same name as the Module.
  2. Refresh the Web application settings:
    1. Go to the Home/_System Structure Group.
    2. Select the Publish Settings Page and click Publishing > Publish.
    3. Go to your Web application and enter the URL /admin/refresh refresh the cache and reload the settings in the Web application.
  3. Write out resource values in Views:
    1. Use the Html.Resource extension method to write out resource values. For example, update your SpecialOffer view link as follows to write out your moreInfoText resource:
      <a href="@Model.Link" class="btn btn-primary" @Html.DxaPropertyMarkup(() => Model.Link)>@Html.Resource("myCompanyExamples.moreInfoText")</a>
    2. Update resources by editing the corresponding Component. The key used to access a resource is always in the format moduleName.resourceName. If you cannot find a resource, the key is returned to aid troubleshooting.
  4. Localizing resources:
    1. Open the module configuration Component located in /ModuleName/Admin to view the Resource Components.
    2. Localize and translate the Resource Component.
    3. Localize and translate resource Components at a lower point in the BluePrint.
    The correct localization of the resource is automatically written out using the Resource helper methods. The current localization is determined at the beginning of each request (based on the request URL) and used where needed to ensure the right content and resources are loaded.
  5. Publish the changes:
    1. Navigate to the Building Blocks/Settings/Core/Site Manager/ Folder.
    2. Open the HTML Design Configuration Component.
    3. Increment the Version Number.
    4. Publish the Publish HTML Design page.