Creating Connected Postings

There are a few "moving" parts to connected postings. One of the most basic rules for connected postings is that you must have connected templates (or use the same template). The connected templates set up the environment to allow content sharing between the connected postings. In order to create a connected template, you need to use VS.NET to create a template file and a connected TGI, and then bind the TGI to the template file. The new template file does not have to contain the same number of Template objects as the original TGI. However, you cannot add additional placeholder definitions in the connected TGI unless you want the other connected templates to share those same definitions (which may be desirable).

In the following sections, we'll first discuss creating a connected set of templates. We'll show you how to create a connected TGI and wire the placeholder definitions to the various placeholder controls on your new template file. In our demonstration, we'll show how you can have fewer placeholder controls than definitions to allow you to selectively decide what content shows up when you create postings on the new template.

Creating Connected Templates

As we mentioned, in order to create connected postings, you must first create connected templates. In our example, we're going to create an alternative version of our press release template, which eliminates the call-out caption and call-out image on the right side of the page. To refresh your memory, refer to Figure 15-1 for a screen shot of an existing press release.

Figure 15-1. A press release on the BOTS Consulting Web site

graphics/15fig01.jpg

As a first step, we should review what placeholders the existing Press Release Detail template contains. In our existing press release template, we have five placeholders: the Calendar placeholder (which is a custom placeholder we will build later in the book), the BodyCopy placeholder, the Disclaimer placeholder, the CallOutImage placeholder, and the CallOutImageCaption placeholder. All the placeholders, except the CallOutImage placeholder, use the HTML placeholder definition. As we mentioned earlier, we want to create a connected template that does not contain the call-out image or caption; the placeholder definitions will still exist; we simply won't connect them to a physical placeholder control.

When we first created the BOTS site, we took the time to create a generic template, which represented the basic structure of all our templates (as we mentioned in Chapter 12). Now, we are simply going to copy this generic template file and create our new file. In our example, we're going to call the new template file Press Release sans CallOut.

Once you have your new template file set up, you just need to add the placeholders you want to have. For this example, we want to reproduce three of the five placeholders: the Calendar placeholder, the BodyCopy placeholder, and the Disclaimer placeholder. We'll add the three HTML placeholder controls to our template and give them the same names as our placeholder definitions (they don't have to be named the same; we're doing this for convenience). In Figure 15-2, you can see what our new template looks like.

Figure 15-2. The new Press Release sans CallOut template in the BOTS Consulting site

graphics/15fig02.jpg

Now that we have our new template, we need to create our connected TGI. To create a new, connected TGI, open the Template Explorer in VS.NET. If you don't already have the window docked somewhere, you can call it up by going to the View menu, picking Other Windows, and then choosing MCMS Template Explorer. Once you've located the Template Explorer window, find the template you want to connect. In the BOTS site, we're going to use the Press Release Detail template. To make your connected TGI, right-click the TGI in the Template Explorer and choose Create Connected from the context menu. Figure 15-3 shows this operation. You may notice in Figure 15-3 that we have a small chainlike icon on the upper right corner of our TGI. The chain icon indicates that your TGI is connected; our template already happened to have been connected to another template, but it won't make a difference in this operation. Once you've created your connected TGI, your original and connected TGIs will also have the chain icon.

Figure 15-3. Creating a connected TGI in the Template Explorer

graphics/15fig03.gif

Once we have our TGI and our template file, we simply need to connect the TGI to the template file and the placeholders to the placeholder definitions in the TGI. First, set the TGI TemplateFile property to point to your new template in our case, the pressreleasesanscallout.aspx file. Next, starting with the Calendar placeholder, we set the PlaceholderTo Bind property of each of the placeholder controls we added earlier to the appropriate definition Calendar to Calendar, BodyCopy to BodyCopy, and Disclaimer to Disclaimer. Once we're finished with that, our new template can now be used by our content contributors to create connected postings. In Figure 15-4, you'll see the completed template file, along with the resulting TGI.

Figure 15-4. The finished template with the new, connected TGI

graphics/15fig04.jpg

There are a few things for you to be aware of now that you've created your connected TGI. Because connected TGIs share a common set of definitions, if you check out a connected TGI, CMS will warn you that it will lock all other connected TGIs. Although this isn't generally a big problem, it could prevent others from changing aspects of the other TGIs while you have the connected TGI checked out. Further, if you make a change to a connected TGI, the change will cascade to the other connected templates. For example, if you add another definition or a custom property, that definition or custom property will now exist in all the other TGIs. Also, all the connected templates will be shown in bold (unsaved changes) until you save the changes or check in the TGI.

Using the Web Author

Now that you have your connected template, you're ready to create a connected posting. One of the easiest ways to create a connected posting is with the Web Author. In the edit console there is a link for Create Connected Page just below the Create New Page link. Use the following instructions to create a connected posting.

  1. Navigate to the posting that will serve as the original posting.

  2. Switch to Edit mode.

  3. Click Create Connected Page (shown in Figure 15-5).

    Figure 15-5. The Create Connected Page link in the edit console

    graphics/15fig05.gif

  4. After clicking the Create Connected Page link, you'll see the Create Connected Page Wizard, which allows you to browse through the channels in your site to specify the location of your connected page (shown in Figure 15-6).

    Figure 15-6. The Create Connected Page interface to select a new channel

    graphics/15fig06.gif

  5. After you've chosen your channel, you can select from a list of connected templates. In our case, we have three templates we can choose from: the original template plus two connected templates we've created. We're going to use the template we just created: Press Release sans CallOut (shown in Figure 15-7).

    Figure 15-7. Choosing a connected template

    graphics/15fig07.gif

  6. After you've chosen the template you wish to use, CMS will redirect you to the new posting, in authoring mode. As expected, only three of the original five placeholders are shown in our new connected page. In Figure 15-8, notice, however, that the placeholders also contain content; this is the content carried over from the original posting. Also make note that the BodyCopy placeholder has a new symbol in the upper right corner of the placeholder. This new symbol, which looks something like two sheets of paper connected by a wire, indicates that this posting is connected and, specifically, that the placeholders are sharing content with another posting.

    Figure 15-8. The new posting in authoring mode

    graphics/15fig08.jpg

  7. Now, simply save your new posting. When you click Save and Exit, you'll be prompted to enter a new display name. However, the Name property won't be editable, since the name will remain the same as the original posting. We did not provide a figure for this, since you can't tell when the color image is converted to a black-and-white screen shot.

  8. You have successfully created a connected posting. At this point, you can choose to submit the posting, or if you have the authority, you can approve it on the spot.

As you can see, there isn't much to creating a connected posting using the Web Author. In fact, this is the easiest way of creating alternate versions of postings in your site. If you wanted to run a report to see the other connected postings for this posting, you should notice another edit console menu item, Go to Connected Page. This option will allow you to see the other connected postings, and either preview or navigate directly to them. Figure 15-9 shows the connected posting report.

Figure 15-9. Go to Connected Page report

graphics/15fig09.gif

Now that we know how to create a connected posting in the Web Author, let's examine how you can accomplish the same thing with the PAPI.

Using the PAPI

By now, you should be familiar with the creation of a connected posting in the Web Author. We'd now like to show you how to accomplish the same thing using the PAPI. First, let's review the prerequisites for creating a connected posting.

  • The connected posting must use a different, connected template if you create it in the same channel as the original posting.

  • If you create the connected posting in a different channel, you can use the same template as the original posting.

  • Any operation against the content of any of the connected postings will be reflected across all the postings.

  • The authenticated user must have the authority to create postings in both the source and destination channels.

For the purposes of our demo, we're going to create an ASPX page to hold all of the code. We'll name this ASPX page ConntectedPostings. aspx. In actuality, creating an "out of process" ASPX page creates some additional work for us, but it eliminates the need to create a posting based on a template with exactly the same code as our ASPX page; the choice is ultimately yours. An explanation of what we're doing in our ASPX page follows.

  • First and foremost, we must be in Update mode in order to affect the repository. If our page were a posting in CMS, we could retrieve the property UrlModeUpdate and redirect to it. Since this is an out-of-process page, however, we need to redirect to the page with NRMODE=Update specified in the query string.

  • Once we're in Update mode, we'll need to authenticate as a user who has authority to create postings in the source and destination channels. Because the BOTS site has guest access enabled, when our page starts, CMS will log us in as the guest account. In our code, we're redirecting to the login.aspx page to allow us to authenticate. Once we're authenticated, the login page will return us to our ASPX page automatically.

  • Next, we pass a posting and a destination channel. The posting will provide us with a collection of connected templates. Alternatively, we could retrieve the posting's Template object and then get the connected templates, but the way we did it is a bit shorter. With the collection of connected templates, we can create the connected postings using the original posting and the connected templates. The destination channel is where the connected postings will end up.

  • Once we have the collection of connected templates, we iterate through each of them and create a connected posting. Normally, you're more likely to create a single connected posting at a time. However, we wanted to demonstrate how you could create a number of connected postings at once.

  • As we create each connected posting, we report what template was used to create the posting.

  • Once we're finished, we report the operation has completed.

NOTE: The BOTS site uses Forms authentication, which allows us to log in to CMS as a user that's different from the current Windows user. If we were using Windows authentication, the current user would need the appropriate permissions to create the connected postings. In that case, we wouldn't use the login page at all; CMS would automatically authenticate us.


In Listing 15-1 you can see the code in our ASPX page. The code is commented to help you match it to the preceding list of bullet items.

Listing 15-1 The code for ConnectedPostings.aspx

[View full width]

 protected System.Web.UI.WebControls.PlaceHolder PageOutput; private CmsHttpContext myContext; private void Page_Load(object sender, System.EventArgs e) {       // Check to see if the NRMODE querystring has been set.  If not       // redirect back to the page with the parameter set       if(Request.QueryString["NRMODE"] != "Update")       {Response.Redirect("/botsconsulting/utilities/connectedpostings.aspx?NRMODE=Update");}       // Create a reference to the current context       myContext = CmsHttpContext.Current;       // Find the original posting and channel; we've hard coded paths       // for demonstration purposes.  Normally you would pass in the       // beginning values.       Channel connectedPostingChannel = (Channel)myContext.Searches.GetByPath("/Channels graphics/ccc.gif/botsconsulting/services");       Posting originalPosting = (Posting)myContext.Searches.GetByPath("/Channels graphics/ccc.gif/botsconsulting/about/press/1132003771");       // Make sure that we got back both objects       if (originalPosting != null && connectedPostingChannel != null)       {             // We got the objects we wanted, so update the PageOutput server control             this.PageOutput.Controls.Add(new LiteralControl("Found both the channel and graphics/ccc.gif the posting<br>"));             this.PageOutput.Controls.Add(new LiteralControl ("Attempting to create the new graphics/ccc.gif connected posting(s)<br>"));             // Call the CreateConnectedPostings function             CreateConnectedPostings(originalPosting, connectedPostingChannel);       }       // We didn't get back the objects we wanted, so just end.       else       {             this.PageOutput.Controls.Add(new LiteralControl("Could not find either the graphics/ccc.gif destination channel or original posting<br>"));             this.PageOutput.Controls.Add(new LiteralControl("The current user " + graphics/ccc.gif myContext.User.ServerAccountName + " may not have rights<br>"));             this.PageOutput.Controls.Add(new LiteralControl("or the objects may not graphics/ccc.gif exist<br>"));       } } private void CreateConnectedPostings(Posting startPosting, Channel destinationChannel) {       // Make sure the current user has authoring rights       // in the source and destination channel       if (destinationChannel.CanCreatePostings && startPosting. Parent.CanCreatePostings)       {             // Get a list of the connected templates for the passed in posting             TemplateCollection myConnectedTemplates = startPosting. ConnectedTemplates;             // Check to make sure we got a collection back             if (myConnectedTemplates != null)             {                   // Loop through the entire collection and create a connected                   // posting with each template                   foreach(Template connectedTemplate in myConnectedTemplates)                   {                         this.PageOutput.Controls.Add(new LiteralControl("Creating new graphics/ccc.gif connected posting based on the "                               + connectedTemplate.Name + " template.<br>"));                                           destinationChannel. CreateConnectedPosting graphics/ccc.gif(connectedTemplate,startPosting);             // Commit the changes to the repository and release any             // locks on the objects             myContext.CommitAll;                   }                   this.PageOutput.Controls.Add(new LiteralControl("Operation completed graphics/ccc.gif successfully.<br>"));             }       }       else       {             // If we're not logged in with a user ID that has authority             // to create connected postings, redirect to the login             // page.  This will continue to fire until the appropriate             // credentials are provided.             Response.Redirect("/botsconsulting/login.aspx? returnurl=" + HttpUtility graphics/ccc.gif.UrlEncode("/botsconsulting/utilities/connectedpostings.aspx?NRMODE=Update"));       } } 

In the preceding code sample, we were able to create a number of connected postings all at once. The code isn't complex, since CMS takes a lot of the work out of the operation. However, you should be careful to check for locks on the objects. In general, objects that are free of locks will be "owned" by everyone. If the posting you're using to create connected postings is owned by a specific user, it's likely that it's still going through a workflow process or in the midst of an edit.



Microsoft Content Management Server 2002. A Complete Guide
Microsoft Content Management Server 2002: A Complete Guide
ISBN: 0321194446
EAN: 2147483647
Year: 2003
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net