Month: October 2012

CSS Aggregation targeting specific browser version in Ektron

I have mentioned the benefits of CSS aggregation previously when using Ektron: reduce HTTP requests, reduce overall page download size and boost performance.

One thing I discovered recently was the ability to use Ektron’s CSS aggregation feature but to be able to specify a target web browser.

You have probably seen conditional comments in CSS before:

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

If you want to use this feature in tandem with CSS aggregation then you need these two lines of code:

Ektron.Cms.Framework.Content.ContentManager contentMgr = new Ektron.Cms.Framework.Content.ContentManager();
Ektron.Cms.API.Css.RegisterCss(this, contentMgr.SitePath + "/css/file.css", "css_file", Ektron.Cms.API.Css.BrowserTarget.IE7);

As you can see from the final parameter in the RegisterCSS() method, you can specify a target browser. In the example above I have specified IE7.

Get content item in preview mode using Ektron API

When content has been checked-in and has a status of “I” it will appear on the site if the site is in preview mode. Using preview mode allows you to see what content will look like on your site before you click the publish button.

The code below simulates the site being in preview mode and uses the Framework API:

Ektron.Cms.Framework.Core.Content.Content contentApi = new Ektron.Cms.Framework.Core.Content.Content(ApiAccessMode.Admin);
contentApi.InPreviewMode = true;
CB.Text = contentApi.GetItem(ContentBlockId).Html;

Add content item in a checked-in state using Ektron API

During a recent content migration exercise I had need to bulk insert a lot of content that must be added in a checked-in state, i.e. the content must not have been published previously.

I was unable to find a solution using the Framework API or even the version 7 API (e.g. Ektron.CMS.API.Content.Content) so I had to delve deeper into the past!

The code below actually comes from the Workarea itself and uses the awful Visual Basic Collections (arrrrggghhh) :

using Microsoft.VisualBasic;

public partial class CheckIn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Use a VB Collection to define the content item

        Collection objCol = new Collection();
        {
            objCol.Add(1, "ContentType"); // 1 = HTML / SmartForm
            objCol.Add("&lt;root&gt;&lt;MyField&gt;Value goes here&lt;/MyField&gt;&lt;/root&gt;", "ContentHtml"); // Content (XML)
            objCol.Add("my comment", "Comment"); // Comment field
            objCol.Add(0, "ContentID"); // Content ID (zero for new content)
            objCol.Add(2057, "ContentLanguage"); // UK English
            objCol.Add("my teaser", "ContentTeaser"); // Teaser / Summary field
            objCol.Add(72, "FolderID"); // Folder where content should be added to
            objCol.Add("my search text", "SearchText");
            objCol.Add("", "GoLive");
            objCol.Add("", "EndDate");
            objCol.Add(2, "EndDateAction");
            objCol.Add("my content title", "ContentTitle"); // Content title
            objCol.Add(true, "AddToQlink");
            objCol.Add(true, "IsSearchable");
            objCol.Add("7", "MultiXmlID"); // Smartform Id
        }

        long intContentId = 0;

        ContentAPI m_refContApi = new ContentAPI();

        // The old API uses current use by default, so switch to Internal Admin
        // in order to be able to add content.
        // Remember the ID of the original user so we can switch back to that again afterwards.
        long iOrig = m_refContApi.RequestInformationRef.CallerId;
        m_refContApi.RequestInformationRef.CallerId = 
          (long)Ektron.Cms.Common.EkEnumeration.UserGroups.InternalAdmin;
        m_refContApi.ContentLanguage = 2057;

        // Adds content, then checks it in
        intContentId = m_refContApi.EkContentRef.AddNewContentv2_0(objCol);
        m_refContApi.EkContentRef.CheckContentInv2_0(intContentId);

        // Set API back to original user ID
        m_refContApi.RequestInformationRef.CallerId = iOrig;
    }
}

Hopefully this code will save you having to dig through the old workarea code.