Targetting non-Office placeholders with the Word Authoring Connector

by Dan Matthews 29. March 2007 07:19

Note: This article only refers to content placeholders, ie text, although much of the article would apply equally to attachment placeholders, albeit requring a little more effort.

When handling postings in MCMS using the Word Authoring Connector, there is no built-in way to target multiple or specific placeholders. The only way to ensure that the correct placeholder content is populated is to create the template definition with an OfficeHtmlPlaceholder definition or only place one HtmlPlaceholder definition on the page (the 'first' one is used if there are multiple HtmlPlaceholders - if there are multiple OfficeHtmlPlaceholders the content is placed in all of them).

Whilst this will meet most needs adequately, there are several cases where this could be a limitation. For example:

  • Targetting custom placeholders (the WAC will only target HtmlPlaceholder and OfficeHtmlPlaceholder)
  • A requirement to target multiple placeholders... don't expect a clean solution for this one :)
  • Requirement to target a specific HtmlPlaceholder which isn't 'first'
  • Requirement to target something which isn't a placeholder (possibly a custom property, for example)

Although some customisation of the WAC is possible, essentially it's a 'black box' and what you see is what you get. It's targetting logic is buried within and can't be tweaked. Fortunately, there's a fairly easy way to get around the limitations above.

The core concept is to add an OfficeHtmlPlaceholder on the template which remains hidden. This placeholder will always be targetted by the WAC (if there's more than one on the template, they'll all be targetted). The placeholder will be used as a 'holding area' for the content.

When the WAC is used to update/create a posting, the posting will then be at a 'Saved' state awaiting Approval. This is where the little bit of magic comes in.

As the posting should always be opened up to be approved (or rejected), then we can make use of the posting load event to take the content from our OfficeHtmlPlaceholder holding area and put it into the correct place/s.

A practical example of this follows. A template has two HtmlPlaceholders defined, and the code shown targets the second one. This could occur if, for instance, you want the body to be added using the WAC and then the title to be added at the approval stage. The steps can be followed to demonstrate the technique (reasonable prior experience of MCMS and the WAC is assumed).

  1. Create a Template Definition with two HtmlPlaceholder definitions called 'HtmlTitle' and 'HtmlBody'. Also create an OfficePlaceholderDefinition called 'OfficeHtmlHoldingContainer'. There's no need to put any restrictions on any of these placeholders as that will only complicate matters.
  2. Create a .ASPX template file and hook it up to the template definition created in (1).
  3. Add three HtmlPlaceholderControl controls to the template, and hook each up to one of the placeholder definitions. Ensure that the control hooked up to OfficeHtmlHoldingContainer has the Visible and EnableAuthoring properties both set to False.
  4. Create an empty class called AuthoringConnectorSupport.cs.
  5. Paste the following code into the new class created in (4):

      public AuthoringConnectorSupport() // just an empty constructor
      {
      }
      
      ///
      /// Swap the Office placeholder content into targetted placeholder, if valid
      ///
       public void SwapOfficeContentInIfValid()
      {
       Posting oPosting = CmsHttpContext.Current.Posting;   if(oPosting.Placeholders["OfficeHtmlHoldingContainer"] != null && oPosting.Placeholders["HtmlBody"] != null) // ensure basic required placeholders are present
       {
        if(oPosting.Placeholders["OfficeHtmlHoldingContainer"].Datasource.RawContent != "")
        {
         oPosting.Placeholders["HtmlBody"].Datasource.RawContent = oPosting.Placeholders["OfficeHtmlHoldingContainer"].Datasource.RawContent;
         oPosting.Placeholders["OfficeHtmlHoldingContainer"].Datasource.RawContent = "";     // uncomment this next line if you want the above to happen anyway, even if authoring is cancelled
         //CmsHttpContext.Current.CommitAll();
        }
       }
      }
  6. Add the following code into the Page_Load event of the template created in (2)

       // create an AC support object
       [insert namespace].AuthoringConnectorSupport oACSupport = new [insert namespace].AuthoringConnectorSupport();
       
       // ensure Office content is swapped in, if required
       oACSupport.SwapOfficeContentInIfValid();

  7. Set up a publishing task for the WAC in the PublishingTasks.xml file.
  8. Create a posting of this template type using the WAC.
  9. Approve the posting.

What should have happened is that at (9), the content which you entered in Word has been moved into the HtmlBody placeholder, which was the second HtmlPlaceholder.

This technique can be used to target any placeholder which will take textual content, such as a custom placeholder, and can be tweaked in the AuthoringConnectorSupport class if different properties are used for content.

An extension of this technique can be used to target multiple placeholders, although the solution is not particularly 'clean'. In the Word document 'tags' can be added that will be read by the AuthoringConnectorSupport class. These tags could be placeholder names, or just words that get picked up and checked in the class via a switch statement, for example. Macros could even be used in Word to insert these 'tags'. The AuthoringConnectorClass would merely scan through the incoming content for these tags, split the string up and then share it out across the placeholders as required.

 

 

Tags:

MCMS

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar