On most projects I have worked on, at some point we have needed some Tridion uris in the web application, be it to load keywords from a taxonomy, or executing broker queries for items based on a certain schema ID, and return dynamic component presentations using a given Template uri. This article shows you a simple TBB to publish these config values.
Often on projects, in order to get results quickly, these uris get hard coded at first, and then perhaps moved into the appSettings section of web.config, to make them configurable across environments. Soon as more and more functionality is developed you end up with 10 or more uris in the config. Then you roll out multiple websites, each with their own web.config, which all need to be kept up to date. Things soon get out of hand…
A much better solution is to publish the configuration from the CMS itself – theres no need to keep everything updated manually across sites, and the differences between environments are managed automatically. Heres a TBB that does just this:
If you pop this into a Page Template, with file extension XML, you can publish a page with this template (no need to add any components to the page) and end up with something like the following:
Note that the logic in the TBB does some filtering so that not all items are added to the config. As you are only likely to need to want the uris of templates that have published dynamic components, or taxonomies that have been published it checks to see if a template or taxonomy has been published before adding it to the config. Also, we only add normal schemas, not parameter, metadata, multimedia etc.
All you need now is to create a simple class to read your config and provide uris to the web application based on the Key (which is derived from the item title).