Table of Contents

Class ContentModule

Namespace
Dynamicweb.Modules
Assembly
Dynamicweb.dll
Responsible for outputting the HTML for your module in the frontend. A module can be attached to a paragraph in the administration. ContentModule is responsible for having the paragraph return some module output. Inherit this class and override the GetContent method to return the HTML for the module as a string.
public abstract class ContentModule : IModule
Inheritance
ContentModule
Implements
Inherited Members

Examples

using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Modules;

namespace Dynamicweb.Examples
{
	[AddInName("ModuleSystemName")]
	public class ContentModuleSample : ContentModule
	{
		public override string GetContent()
		{
			//Get an instance of a template object
			var template = new Dynamicweb.Rendering.Template("ModuleSystemName/Template.cshtml");

			//Set a tag named "Text" with the value from the HelloText property
			template.SetTag("Text", Properties.Values["HelloText"].ToString());

			//Add the page id executing the page with the paragraph where this module is attached
			template.SetTag("PageID", this.Pageview.ID);

			//Return the parsed template to the event handler
			return template.Output();
		}
	}
}
using Dynamicweb.Core.UI.Icons;
using Dynamicweb.Modules;
using Dynamicweb.Modules.Annotations;

namespace Dynamicweb.Examples
{
    [ModuleName("ModuleSystemName", "Module name")] // Required.
    [ModuleDescription("Some description of thís module")] // Optional.
    [ModuleIcon(KnownIcon.Tasks)] // Optional. The name of a known icon in Dynamicweb which will be displayed in the management UI. See documentation for details.
    [ModuleAccess(true)] // Optional. Setting this to false will disable this module by default. Default value is true.
    public class ContentModuleWithAnnotationsSample : ContentModule
    {
        public override string GetContent()
        {
            return "Hello world";
        }
    }
}

Remarks

The class created by inheriting ContentModule needs and attribute AddInName or ModuleName with a module system name specified. The module system name needs to be a-z and 0-9 and no spaces etc.

Constructors

ContentModule()

Initializes a new instance of the ContentModule class.
public ContentModule()

Remarks

Instance created by Dynamicweb when attaching a module to a paragraph.

Properties

Pageview

Gets the PageView instance and gives you information about the current page that your module is used in. It gives you access to properties like the Page, the AreaID, information like style sheets and templates that are effective and it provides access to the current User of the page.
public PageView Pageview { get; set; }

Property Value

PageView

Paragraph

Gets or sets the paragraph rendering the instance of this module.
public Paragraph Paragraph { get; set; }

Property Value

Paragraph

ParagraphId

Gets the paragraph ID of the current paragraph attaching the module
public int ParagraphId { get; set; }

Property Value

int

Properties

Gets or sets a Properties object with values of the settings set when this instance of the module was attached to a paragraph.
public Properties Properties { get; set; }

Property Value

Properties

Examples

template.SetTag("Text", Properties.Value("HelloText"))
template.SetTag("Text", Properties.Values["HelloText"]);

Methods

GetContent()

Override this method and return the HTML output for the module.
public virtual string GetContent()

Returns

string
Must return the markup that renders the module.

Examples

using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Modules;

namespace Dynamicweb.Examples
{
	[AddInName("ModuleSystemName")]
	public class ContentModuleSample : ContentModule
	{
		public override string GetContent()
		{
			//Get an instance of a template object
			var template = new Dynamicweb.Rendering.Template("ModuleSystemName/Template.cshtml");

			//Set a tag named "Text" with the value from the HelloText property
			template.SetTag("Text", Properties.Values["HelloText"].ToString());

			//Add the page id executing the page with the paragraph where this module is attached
			template.SetTag("PageID", this.Pageview.ID);

			//Return the parsed template to the event handler
			return template.Output();
		}
	}
}

Remarks

The markup returned is what is inserted into the template tag ParagraphModule in the paragraph template.

InitializeModule(Paragraph)

Initializes the instance of a content module. Dynamicweb calls this method when a ContentModule instance is created when attached to paragraph. Can be overridden.
public virtual void InitializeModule(Paragraph paragraph)

Parameters

paragraph Paragraph
The paragraph creating the instance of this module

Remarks

Used internally. Dynamicweb handles the initialization and this method should normally not be called, but only overriden if needed.

InitializeModule(Paragraph, PageView)

Initializes the instance of a content module. Dynamicweb calls this method when a ContentModule instance is created when attached to paragraph. Can be overridden.
public virtual void InitializeModule(Paragraph renderingParagraph, PageView pageviewContext)

Parameters

renderingParagraph Paragraph
The paragraph creating the instance of this module
pageviewContext PageView
An instance of the current pageview being showed

Remarks

Used internally. Dynamicweb handles the initialization and this method should normally not be called, but only overriden if needed.

RequestContext(string)

Gets the value of Name in HTTP query string or post variables. Instead of using Request.QueryString or Request.Form. INFO: Calling this function is context sensitive to the paragraph the module is attached to. That means it will only return a value if PID=123 equals the ParagraphID of the paragraph currently attaching the module or if PID is not specified. This is usefull when the same module is attached several times on the same page and you want different states of the modules on each paragraph. I.e. adding a querystring variable PageNum=2 would cause 2 instances of the module on the same page to change to page 2 when using normal request. If changed to PID=123&PageNum=2 and using RequestContext would make only one of the instances go to page 2.
public string RequestContext(string name)

Parameters

name string
Name of the value in the request collection

Returns

string
The value of the specified key

Remarks

By default the return value has been SQL Escaped (Database.SQLEscapeInjection)
To top