First Sueetie Smart Placeholder Control Surfaces

When I was initially contemplating how to restrict Sueetie blog comments to Registered Users I thought I’d use a smart placeholder control to display or hide the comment form.  While I went another route on blog comments, the Sueetie UserRolePlaceHolder took form as a very useful control, the first of several Sueetie “smart” PlaceHolders we’ll no doubt be seeing. 

To demonstrate the UserRolePlaceHolder I added a simple welcome greeting to registered users on the Sueetie.org home page.  By contrast, anonymous users don’t see the message.

 

As I’ve said a number of times, simplicity is the cornerstone of Sueetie architecture, and I think it’s exemplified in the new UserRolePlaceHolder control.  First of all, the placeholder, like Sueetie placeholders to come, will most likely be single-function with no guesswork on how to use them.  The UserRolePlaceHolder control displays or hides information based on, um, User Role.

To make the controls even easier to use, the property and content areas are full intellisense-enabled.  Here’s a screenshot of setting the role.

Each placeholder control will contain a TrueContentTemplate and FalseContentTemplate for consistency.  Either a condition is true or it isn’t, with options to display content on either condition.  Those, too, are intellisense-enabled.

True to the “Patterns and Origins” history of Sueetie architecture documentation, it’s time to note that the UserRolePlaceHolder control was written from scratch.  Don’t have any illusions, Chameleon is brilliant, but it’s the LAST thing we want in Sueetie.  The full control source is displayed below. You’ll have to admit that there are very few lines of code here. Definitely not Chameleon in origin.

The trick was instantiating the True and False ContentTemplates on a bound object, in this case the SueetieUser.  A post from Stefan Sedich describing his Templated ASP.NET RSS Feed Reader Control was very helpful in understanding the concepts involved.  Highly recommended.  There are also examples of templating in YetAnotherForum.NET, particularly in the YAF.Controls project Container control.  Templating is also used in Joe Shearn’s Sueetie Content Parts control source.

Look for more Sueetie conditional placeholders in the weeks to come as the need arises.  We’ll try to keep them as simple to use as UserRolePlaceHolder.

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.