Crownpeak Output.aspx Example Cheat Sheet

A cheat sheet in English by GregFinzer

Output.aspx example for Crownpeak

7,459 views 1,895 downloads 1 Oct 2018 History
3.7 avg · 0 ratings

Example input.aspx

Input.ShowHeader("Contact Us");
Input.ShowTextBox("Page Title", "page_title");
Input.ShowAcquireImage("Contact Us Logo", "contact_us_logo");
Input.ShowTextBox("Contact Us Logo Alt Text", "contact_us_logo_alt_text");
Input.ShowWysiwyg("Address", "address", ServicesInput.FullWYSIWYG());
Input.ShowTextBox("Customer Service Phone", "customer_service_phone");
Input.ShowTextBox("Email", "email");
Place in Projec­t\T­emp­lat­es­\Som­eTe­mpl­ateName

Example Output­Helper Class

public static class OutputHelper
{
	public static string OutputImage(OutputContext context, Asset asset, string imageAssetName, string altTextAssetName)
	{
		UploadedFile file = asset.UploadedFiles[imageAssetName];

		if (file.IsLoaded)
		{
			Img img = Img.Load(file);

			if (!img.HasError)
				return string.Format("<img src='{0}' width='{1}' height='{2}' alt='{3}' />", file, img.Width, img.Height, asset[altTextAssetName]);
			else if (!context.IsPublishing)
				return string.Format("Error Loading image {0}. Error: {1}", img.ErrorMessage, imageAssetName);
		}

		return string.Empty;
	}

	public static string OutputMailTo(Asset asset, string emailAssetName, string linkText= null)
	{
		if (!string.IsNullOrEmpty(asset[emailAssetName]))
		{
			if (!string.IsNullOrEmpty(linkText))
				return string.Format("<a href='{0}'>{1}</a>", asset[emailAssetName], asset[linkText]);
			else
				return string.Format("<a href='{0}'>{0}</a>", asset[emailAssetName]);
		}

		return string.Empty;
	}
}
Place in Projec­t\L­ibrary

Example Output.aspx

<h1><%= asset["page_title"] %></h1>
<%= OutputHelper.OutputImage(context, asset, "contact_us_logo", "contact_us_logo_alt_text") %>
<p><%= asset["address"] %></p>
<p><%= asset["customer_service_phone"] %></p>
<p><%= OutputHelper.OutputMailTo(asset, "email") %></p>
Place in Projec­t\T­emp­lat­es­\Som­eTe­mpl­ateName

Result

Result

Other Useful Helpers

<% var siteRootPath = Asset.GetSiteRoot(asset).AssetPath.ToString(); %>
<%= ServicesOutput.RenderCSSLink(siteRootPath + "/css/style.css") %>
<%= ServicesOutput.RenderScriptLink(siteRootPath + "/js/util.js") %>
<%= ServicesOutput.RenderHyperLink(asset, "buy_now") %>

Badges

Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.