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 TemplatesAs 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 siteAs 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 siteNow 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 ExplorerOnce 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 TGIThere 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 AuthorNow 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.
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 reportNow 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 PAPIBy 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.
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.
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 /botsconsulting/services"); Posting originalPosting = (Posting)myContext.Searches.GetByPath("/Channels /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 the posting<br>")); this.PageOutput.Controls.Add(new LiteralControl ("Attempting to create the new 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 destination channel or original posting<br>")); this.PageOutput.Controls.Add(new LiteralControl("The current user " + myContext.User.ServerAccountName + " may not have rights<br>")); this.PageOutput.Controls.Add(new LiteralControl("or the objects may not 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 connected posting based on the " + connectedTemplate.Name + " template.<br>")); destinationChannel. CreateConnectedPosting (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 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 .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. |