johans
  • Posts: 42
  • Joined: 05/06/2012
Hello

I want to add controls in the UserBox control, but i'd rather not change the code in YAF.Controls.UserBox (To be safe when upgrading). Is there such a way?
daveburke
  • Posts: 148
  • Joined: 28/05/2008
Johans,

You're absolutely correct in not wanting to touch the UserBox Control directly in YAF.Controls. We customize UserBox and a few other YAF Controls in Sueetie, as well as do some other customization so we use a separate Sueetie.Forums class which references YAF.Classes.Config, YAF.Classes.Data, YAF.Core, YAF.Types and YAF.Utils. Then we can use code excerpts from various YAF projects as needed.

You can download the Sueetie Open Source Solution called Atomo if you want to see how we're doing it. Attached is a screenshot of our Sueetie.Forums class project in Visual Studio.

Good luck,
Dave

http://sueetie.com 
daveburke attached the following image(s):
johans
  • Posts: 42
  • Joined: 05/06/2012
Thanks for the tip.

I ended up with doing:

	public class GTKUserBox : UserBox {
		public const string CharacterInformation = @"<yaf:characterinformation\s*/>";
		protected override void Render(HtmlTextWriter output) {
			output.WriteLine(@"<div class=""yafUserBox"" id=""{0}"">".FormatWith(ClientID));

			string userBox = CachedUserBox;
			if (string.IsNullOrEmpty(userBox)) {
				userBox = CreateUserBoxContents();
				// cache...
				CachedUserBox = userBox;
			}

			// output the user box info...
			output.WriteLine(userBox);

			output.WriteLine("</div>");
		}

		protected string CreateUserBoxContents() {
			string userBox = CreateUserBox();

			// Character information
			userBox = MatchUserBoxCharacterInfo(userBox);

			return userBox;
		}

		/// <summary>
		/// 	The match user box character information.
		/// </summary>
		/// <param name="userBox"> The user box. </param>
		/// <returns> String with Character Information string added to UserBox . </returns>
		[NotNull]
		private string MatchUserBoxCharacterInfo([NotNull] string userBox) {
			string filler = string.Empty;
			var rx = GetRegex(CharacterInformation);

			if (!DataRow["IsGuest"].ToType<bool>()) {
				filler = YafUser.GetCharacterInfo(UserId);
			}

			// replaces template placeholder with actual character information
			userBox = rx.Replace(userBox, filler);

			return userBox;
		}
	}
}
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved