Skip to main content

News

Fixing Missing Token in For This {0}

Business Man Staring At Screens of Code

I recently encountered an issue where my non-content blocks (site settings, categories, etc.) were producing a “For This” folder with a missing token. This missing token appeared in custom content, as well as add-ons like Geta Categories.

  Missingtoken2

For custom content, two things are required to get a value into that empty token: an XML file under the lang folder and a UIDescriptor. In order to fix an add-on like Geta Categories (which already has the UIDescriptor baked-in), all that is needed is an XML file under the lang folder. This is a pretty simple XML that simply denotes the content type in question and the name you’d like to give it. Like so:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<languages>
  <language name="English" id="en">
    <contenttypes>
      <CategoryData>
        <name>Working Category! </name>
      </CategoryData>
    </contenttypes>
  </language>
</languages>

Simply adding the file for Geta Categories will resolve the issue there since they’ve already included the required UIDescriptor in the package. The result will look like this:
Categoryfix2

For your own custom types, the already-mentioned UIDescriptor is also required. This is a simple bit of code to notify Optimizely what to fill in for what tokens. The XML can be expanded to include multiple types, each with their own user-defined name node.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<languages>
  <language name="English" id="en">
    <contenttypes>
      <SettingsBase>
        <name>Setting</name>
      </SettingsBase>
      <CategoryData>
        <name>Category</name>
      </CategoryData>
    </contenttypes>
  </language>
</languages>


The UIDescriptor is a few lines of code that inherit from the generic UIDescriptor, where T is the content type we want to target. As you can see in the XML, the parent node of the name should be the content type name so that Optimizely can pair it up correctly.

[UIDescriptorRegistration]
public class SettingsBlockFolderDescriptor : UIDescriptor
{
public SettingsBlockFolderDescriptor()
{
IsPrimaryType = true;
}
}

 


With both pieces in place, we’ll now see our XML-defined name appear instead of the empty token, {0}:
 
Allfixed2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Greg Jeffers, Senior Technical Consultant

Greg Jeffers is a Senior Technical Consultant with Perficient. He has been developing software on the Microsoft stack for 20+ years and working with Optimizely for 5. Having been in several roles across multiple industries, Greg brings a holistic approach to development. He is passionate about finding the right balance of people and processes to make users feel comfortable in the application while being performant.

More from this Author

Categories
Follow Us