Using the ContentBlock Server Control

The ContentBlock server control displays the following types of content blocks on an Web page.

Static content block

Using a Static Content Block

A static content block displays one identified content block on a Web page. The following image shows a server control that retrieves content block ID=28 and displays it in the browser.

Content block server control properties

The following are Ektron-specific server control properties. You can find information about native .NET properties such as font, height, width and border style in Visual Studio® help.

  • Authenticated (String)

    Indicates if you are logged into the CMS Explorer and can use it to browse to content, collections, and so on. See Also: Browsing Your Ektron Site Using CMS Explorer.

  • CacheInterval (Double)

    The number of seconds that the server control’s data is cached. The default is 0 (zero). For example, if you want to cache the data for 5 minutes, set to 300. See Also: Caching with Server Controls.

  • DefaultContentID (Long)

    The ID of a content block that appears where you insert this server control. If you don’t know the ID number of the content block, use the CMS Explorer to browse to it. See Also: Browsing Your Ektron Site Using CMS Explorer

    NOTE: If you identify a content block that displays an Office document which will be published as HTML, make sure the template sets <span> tags to display the content as a block.

  • DisplayXslt (String)

    Ignore for a non-XML content block.

  • DoInitFill (Boolean)

    By default, Fill occurs during the Page_Init event. Set to false if you want to postpone the fill-action until later. In this case, Fill is automatically called during the Page Render event. You might do this if you need to set or change a property on the control in code-behind and have it render with your changes shown.

  • DynamicParameter (String)

    Select None - Use Default. This parameter is used for dynamic content blocks.

  • Hide (Boolean)

    Hides or displays the output of the control in design time and run time.

    • True—Hide the control output.
    • False—Display the control output.
  • Language (Integer)

    Set a language for viewing content; shows results in design-time (in Visual Studio) and at run-time (in a browser).

  • SuppressWrapperTags (Boolean)

    Suppresses the output of the span/div tags around the control.

    • True—Suppress wrap tags.
    • False (default)—Allow wrap tags.

    WARNING! If you want to let content authors edit this content using Ektron’s Edit in Context feature, this must be set to false.

  • WrapTag (String)

    Lets a developer specify a server control’s tag.

    • Span (default)—designate an inline portion of an HTML document as a span element.
    • Div—apply attributes to a block of code.
    • Custom—Lets you use a custom tag.
Dynamic content block

Using a Dynamic Content Block

Use a dynamic content block to display a content block whose ID is passed through a URL parameter. You would use this server control with a dynamic template.

The following example shows how you can use the ContentBlock server control to pass the id as a URL parameter. When a user clicks a link that passes the content block ID as a URL parameter, that content block appears. If that content block is not available, content block 1 appears

Dynamic ContentBlock server control properties

The following are Ektron-specific server control properties. You can find information about native .NET properties such as font, height, width and border style in Visual Studio® help.

  • Authenticated (String)

    Indicates if you are logged into the CMS Explorer and can use it to browse to content, collections, and so on. See Also: Browsing Your Ektron Site Using CMS Explorer.

  • DefaultContentID (Long)

    The ID of a content block that appears where you insert this server control. If you don’t know the ID number of the content block, use the CMS Explorer to browse to it. See Also: Browsing Your Ektron Site Using CMS Explorer

    NOTE: If you identify a content block that displays an Office document which will be published as HTML, make sure the template sets <span> tags to display the content as a block.

  • DisplayXslt (String)

    Ignore for a non-XML content block.

  • DoInitFill (Boolean)

    By default, Fill occurs during the Page_Init event. Set to false if you want to postpone the fill-action until later. In this case, Fill is automatically called during the Page Render event. You might do this if you need to set or change a property on the control in code-behind and have it render with your changes shown.

  • DynamicParameter (String)

    Select id. When you do, this server control uses the content block passed as a URL parameter.

  • Hide (Boolean)

    Hides or displays the output of the control in design time and run time.

    • True—Hide the control output.
    • False—Display the control output.
  • Language (Integer)

    Set a language for viewing content; shows results in design-time (in Visual Studio) and at run-time (in a browser).

  • SuppressWrapperTags (Boolean)

    Suppresses the output of the span/div tags around the control.

    • True—Suppress wrap tags.
    • False (default)—Allow wrap tags.

    WARNING! If you want to let content authors edit this content using Ektron’s Edit in Context feature, this must be set to false.

  • WrapTag (String)

    Lets a developer specify a server control’s tag.

    • Span (default)—designate an inline portion of an HTML document as a span element.
    • Div—apply attributes to a block of code.
    • Custom—Lets you use a custom tag.
XML content block

Using an XML Content Block

Use an XML content block to display an XML content block on an Ektron Web page.

XML content block properties

The following are Ektron-specific server control properties. You can find information about native .NET properties such as font, height, width and border style in Visual Studio® help.

  • Authenticated (String)

    Indicates if you are logged into the CMS Explorer and can use it to browse to content, collections, and so on. See Also: Browsing Your Ektron Site Using CMS Explorer.

  • CacheInterval (Double)

    The number of seconds that the server control’s data is cached. The default is 0 (zero). For example, if you want to cache the data for 5 minutes, set to 300. See Also: Caching with Server Controls.

  • DefaultContentID (Long)

    The ID of a content block that appears where you inserted this server control if no other content block is identified, or is not available. If you don’t know the ID number of the content block, use the CMS Explorer to browse to it. See Also: Browsing Your Ektron Site Using CMS Explorer

  • DisplayXslt (String)

    If desired, enter a relative or absolute path to an Xslt that determines the display of the page. If you do not define the DisplayXslt property, the OverrideXslt property specifies an XSLT identified in the Edit Smart Form Configuration screen. See Also: Working with Smart Forms

     

    WARNING! If you specify an external file, do not store this file in the Workarea folder. If you store this file in the Workarea folder, the file will be lost when you upgrade.

  • DoInitFill (Boolean)

    By default, Fill occurs during the Page_Init event. Set to false if you want to postpone the fill-action until later. In this case, Fill is automatically called during the Page Render event. You might do this if you need to set or change a property on the control in code-behind and have it render with your changes shown.

  • DynamicParameter (String)

    To make this content block dynamic, select id. When you do, this server control uses the content block passed as a URL parameter.

  • Hide (Boolean)

    Hides or displays the output of the control in design time and run time.

    • True—Hide the control output.
    • False—Display the control output.
  • Language (Integer)

    Set a language for viewing content; shows results in design-time (in Visual Studio) and at run-time (in a browser).

  • SuppressWrapperTags (Boolean)

    Suppresses the output of the span/div tags around the control.

    • True—Suppress wrap tags.
    • False (default)—Allow wrap tags.
  • WrapTag (String)

    Lets a developer specify a server control’s tag.

    • Span (default)—designate an inline portion of an HTML document as a span element.
    • Div—apply attributes to a block of code.
    • Custom—Lets you use a custom tag.
Retrieving the XML structure of an XML content block

Retrieving the XML Structure of an XML Content Block

Retrieving the XML structure of XML content allows for greater control over developing XSLs. The following example shows how to retrieve the XML structure.

  1. Open a new Web form.
  2. Drag and drop a Content Block server control onto it.
  3. Set the DefaultContentID to an XML content block.

    WARNING! This does not work with HTML content blocks, as there is no XML structure to output.

  4. Drag and drop a textbox on the Web form.
  5. Set the TextMode property to MultiLine.
  6. It is also recommended that you set the width of the text box to at least 400 px.

    NOTE: On the code-behind page, add the following line.
    TextBox1.Text = ContentBlock1.EkItem.Html

  7. Build the project.
  8. View the form in a browser. The XML structure of the content block appears in the text box.
Using the ContentBlock server control programmatically

Using the ContentBlock Server Control Programmatically

The following code displays a content block:

NOTE: Before adding these lines of code, drag and drop a literal box on your Web form.

Dim MyContentBlock As New ContentBlock
  MyContentBlock.DefaultContentID = 8
  MyContentBlock.Page = Page
  MyContentBlock.Fill()
  Literal1.Text = MyContentBlock.EkItem.Html

To display a content block with the content block title:

NOTE: Before adding these lines of code, drag and drop a 2 literal boxes on your Web form.

Dim MyContentBlock As New ContentBlock
  MyContentBlock.DefaultContentID = 8
  MyContentBlock.Page = Page
  MyContentBlock.Fill()
  Literal1.Text = MyContentBlock.EkItem.Title
  Literal2.Text = MyContentBlock.EkItem.Html