ASP: Content rotator component

Please, raise your hand if you know anything about asp content rotator.
This is possibly the less known component available since the introduction of asp 3.0... and possibly the less used. In fact, the component could be used in different situation, and it is worth knowing a little bit about it.
The content rotator component creates an object used to display different contents every time a visitor views your page. Not that bad, isn't it? I've already published a post about random quotes... remember? We are actually talking about something very similar, but - someway - simpler.



The object
In order to benefit from the use of the content rotator component, we have to create an asp object like:
<%
set content_rotator=server.createobject("MSWC.ContentRotator")
%>
Now we can access the object methods. In the content rotator object there are only two methods:
  • ChooseContent
  • GetAllContent
The first displays a content string in a text file.
The second displays all the content in the text file.

How to access the content of the text file
In order to get and display the content of our text file, we use a simple response.write:
<%
response.write(content_rotator.ChooseContent("example.txt"))
%>
The ChooseContent method will get a part of the text file content and show it.
In the above code, we assume our text file is example.txt.

What about the text file?
Our text file (example.txt) can contain text, links, images... anything represented in HTML tags.
Let's see some examples. Our example.txt file could contain:
%% #3
Hello!

%% #3

Good Day!



%% #4
The Web Thought

%% #3
As you can see, you can put anything you like in the text file.
But what's the meaning of those #n? That is an optional number that represents the relative weight of the HTML content string. The content rotator component will display the content according to those parameters. In the above example, it will display the first, the second and the fourth lines 3/10 of the times; the third line 4/10 of the times. That will give you the option to decide how frequently a content is displayed.