Themelia Pro A powerful new development platform built on ASP.NET.
 
Simple Content Viewer v1.0
 
 

Simple Content Viewer ("SCV") is a simple, yet very effective application for displaying static content on a Themelia Pro web site. To see SCV in action, all you have to do to head over to the Themelia Pro documentation.

The basic idea idea behind SCV is that the file system is a very effective place to store documents and doesn't require any setup like a database. Not only that, but the file system automatically gives you the metadata of "Title" in the file by its file name. SCV allows you to use your file system to store documents and the file names to set the titles. Then, by using little codes in the file name, you set a "key", which end-users can use to access the document.

Sample Folder Structure

Take the following folder structure for example:

Given the following base folder:

C:\_CONTENT\Sample\

Given the following structure under this path:

\Docs\First\_default.txt
\Docs\First\Prefixed - This is an example of a prefix key.htm
\Docs\First\{This has a key obtained from} subtraction.htm
\Docs\First\{This shows when nothing else is} selected.htm

\Docs\Second\_title.txt
\Docs\Second\$ - External.htm
\Docs\Second\{Another example of title via} sub {traction}.htm
\Docs\Second\{This is a} text {example}.txt

Web Domain Install

With the above information set, you can then isntall SCV. This is just a matter of installing the SCV web component ("Jampad.SimpleContent.Processing.ContentComponent") into a web domain. For example:

<add name="docs" path="docs" defaultPage="/Page_/Documentation.aspx" catchAllMode="DefaultPage">
    <components>
        <add type="Jampad.SimpleContent.Processing.ContentComponent, Jampad.SimpleContent">
            <parameters>
                <add name="physicalFolder" value="C:\_CONTENT\Sample" />
            </parameters>
        </add>
    </components>
</add>

At this point you're done. Now when a user accesses one of the following paths, the related physical document will load:

/docs/first
/docs/first/prefixed
/docs/first/subtraction
/docs/first/selected

/docs/second/external
/docs/second/sub
/docs/second/text

So, SCV requires the following:

  • the component key be "themelia.simpleContent"
  • physicalFolder parameter be set to the folder base
  • a default page be set on the web domain.

Usage

Now that you know which file is being loaded based on which key, what do you do with that? As you can see in the previously shown web domain configuration, a defaultPage was set and the catchAllMode was DefaultPage. This means that when a part of the web domain is accessed that is not handled by an endpoint, the default page handles the request. This is the typical setup for using SCV.

With this setup, you can access the loaded content, the title, and content-type through Themelia Pro's HttpData class.

//+ this is your strongly-typed data accessor; it's optional, but highly recommended.  Just place it above your class like any other "using".
using Info = Jampad.SimpleContent.Processing.ContentInitProcessor.Info;
//+ you can use the following anywhere after init-processing.
String content = HttpData.GetScopedItem<String>(Info.Scope, Info.Content)
String title = HttpData.GetScopedItem<String>(Info.Scope, Info.Title)
String contentType = HttpData.GetScopedItem<String>(Info.Scope, Info.ContentType)

With this information, you can show the content however you would like. Here is an example of an OnInit method in the previously mentioned default page (for this example in context, see the sample web site that comes with SCV):

//- #OnInit -//
protected override void OnInit(EventArgs e)
{
    //+ set content-type (this will probably always be optional for you)
    Response.ContentType = HttpData.GetScopedItem<String>(Info.Scope, Info.ContentType);
    //+ set content
    litContent.Text = HttpData.GetScopedItem<String>(Info.Scope, Info.Content);
    //+ set title
    String title = HttpData.GetScopedItem<String>(Info.Scope, Info.Title);
    litTitle.Text = title;
    Page.Title = title;
    //+
    base.OnInit(e);
}

Key Creation

How did those logical paths relate to those physical files? The answer is simple: via the stated key. In each logical branch (e.g. first, second), you have a set of keys created based from the file titles. The keys are set by putting certain codes in the file name.

The two most basic ways of setting a key are via prefixing and via sutraction. To create a key via prefixing, just put the key before a single - in the file name. To create a key via subtraction, just wrap all parts that are NOT in the title in {} (the key will be all text in the file name that hasn't been subtracted, minus any spaces-- so "This is {my} key" creates a key of "thisiskey"). Below is an example of prefixing and another of subtraction:

\Docs\First\Prefixed - This is an example of a prefix key.htm \Docs\First\{This has a key obtained from} subtraction.htm

In the prefixed example, "prefixed" is the key (keys are always saves as lower-case). In the subtraction example, "subtraction" is the key.

It's important to note that you're not restricted to HTML. You can use text too. To use text, just give your file name a "txt" extension. Nothing more is required. When the extension is "txt", the content-type will be text/plain and when the extension is "htm" (or "html"), the content-type will be text/html. Remember, though, since the web only sends on content-type per response, your entire page will be text. So you don't want to mix HTML and text.

If you want more complex titles, like titles with character's not supported by the Windows file system or titles with - in them, you can use another technique: the _title.txt technique.

In this model, you just name your file with the key, prefixed with "$ -", then store your actual title in the _title.txt file. For example, if you wanted a title of "ProductA: Something you need?", you have to use this technique (since Windows supports neither : nor ?). For this, you would name your file something like "$ - ProductA Something.htm". Then, in that specific folder's _title.txt file, place the following:

ProductASomething,ProductA: Something you need?

The format of the _title.txt file is this: one entry per line with the key and title separated by a single comma (,).

In the original example shown, you were able to access a path like the following:

/docs/first

However, if you look at the files, you won't see anything mapped directly to this. This is another SCV technique. If you want to set an existing document as that path segment's default document, you put the key of the default document prefixed with a $ in the _default.txt file.

For example, in the "first" physical folder, there was the following file:

\Docs\First\{This shows when nothing else is} selected.htm

To set this as the default document, create a _default.txt file in that specific folder (i.e. \Docs\First\). In this file place the following:

$Selected

That's it. Now, when /docs/first, is accessed, the content from "{This shows when nothing else is} selected.htm" will be loaded.

Download Here