+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Generic Content 'Shortcut/Placeholder/Bookmark'?

Generic Content 'Shortcut/Placeholder/Bookmark'?

5 posts, 1 answered
  1. Jess Askey
    Jess Askey avatar
    20 posts
    Registered:
    25 Feb 2010
    22 Oct 2010
    Link to this post
    Hi everyone...

    In the website I am designing, we have a list of states that is configured in the database. One of the common things we do in generic content is to list the state abbreviations. These lists of states are spread all over the site and are generally just in the middle of text as needed (sometimes right in the middle of sentences). Besides making a whole .ascx and sandwiching it between two other generic content controls, is there any way that I can make a custom bookmark/placeholder/shortcut for this state list so that when generic content is rendered, it would replace my bookmark with the data driven state list?   Im thinking something like..

    The product listed here is only available in [OURSTATES]. If you are not located in one of these states, they you will not be able to get this product.

    This would eventually show as something like....

    The product listed here is only available in NY,PA,OH,MD and TX. If you are not located in one of these states, they you will not be able to get this product.

    So, are there events that I can attach to for Generic Content managers that might allow me to do a search and replace for reserved bookmarks that I create?

    thanks...

    j
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Oct 2010
    Link to this post
    Hi Jess,

    We do not have this functionality out of the box. You can subscribe for static events of ContentManager class - Executed and Executing inside Application_Start. You can get the item ID from the command arguments and using regular expression you can find/replace the content you want.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jess Askey
    Jess Askey avatar
    20 posts
    Registered:
    25 Feb 2010
    03 Nov 2010
    Link to this post
    Hi Ivan...

    Thanks for the reply... I tried this by creating an event handler and binding it in Application_Start but from what I can tell, the e.CommandName only seems to happen on item updates, deletes, edits and inserts. I need to intercept it when the item is viewed which didn't seem to call the hooked events ('executing' in this case). Since the bookmark I want to created might change after (lets say) the content is created, I need to do the search and replace on render rather than on creation.  I didn't see any e.CommandName values that fit this approach.

    Am I out of luck?

    thanks
    jess
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Nov 2010
    Link to this post
    Hi Jess,

    You have to use HttpModule or HtrtpHandler. There are no commands thrown when you view an item.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Jess Askey
    Jess Askey avatar
    20 posts
    Registered:
    25 Feb 2010
    05 Nov 2010
    Link to this post
    Hi Ivan...

    Ahhhh, got it. I wasn't even familiar with this functionality for ASP, so thank you. This is what I ended up doing, it works *wonderfully*.

    This example allows me to put a text 'bookmark' in any content and it will be programmatically replaced with appropriate values from my data driven data source.

    "[[[STATES]]]"  will be replaced with "AK, AZ, CA, CO, PA, WY"

    public class GlobalApplication : HttpApplication
    {
        public GlobalApplication() {}
     
        public static System.Collections.Hashtable GlobalDictionary = null;
     
        void Application_Start(object sender, EventArgs e)
        {
            //init our dictionary
            GlobalDictionary = new System.Collections.Hashtable();
            //this is just simple for example, but in my code I actually load the
            //dictionary from a database
            GlobalDictionary.Add("[[[STATES]]]", "AK,AZ,CA,CO,PA,WY");
        }
    }

    I have a base class for all my master pages, so in my MasterBase PageInit, I assign a Response filter...

    protected override void OnInit(EventArgs e)
    {
         Page.Response.Filter = new GlobalDictionaryFilter(Page.Response.Filter);
    }


    Here is the response filter class to actually do the filtering...

    public class GlobalDictionaryFilter : MemoryStream
    {
        private Stream outputStream = null;
     
        public GlobalDictionaryFilter(Stream output)
        {
            outputStream = output;
        }
     
        public override void Write(byte[] buffer, int offset, int count)
        {
            string bufferContent = UTF8Encoding.UTF8.GetString(buffer);
            foreach (string key in GlobalApplication.GlobalDictionary.Keys)
            {
                bufferContent = bufferContent.Replace(key, GlobalApplication.GlobalDictionary[key].ToString());
            }
            outputStream.Write(UTF8Encoding.UTF8.GetBytes(bufferContent), offset, UTF8Encoding.UTF8.GetByteCount(bufferContent));
            base.Write(buffer, offset, count);
        }
    }

    Viola!!

    jess
Register for webinar
5 posts, 1 answered