示例#1
0
        /// <summary>
        /// Gets the HTML for file.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <returns></returns>
        private string GetHtmlForFile(Media media)
        {
            // check that its not null
            if (media != null)
            {
                // get the img src
                var file = media.GetProperty<string>(Constants.Umbraco.Media.File);

                // check that the file has a value
                if (!string.IsNullOrEmpty(file))
                {
                    // define the anchor tag
                    var anchor = "<a href=\"{0}\">{1}</a>";

                    // format the anchor tag
                    return string.Format(anchor, file, media.Text);
                }
            }

            // fall-back return an empty string
            return string.Empty;
        }
示例#2
0
        /// <summary>
        /// Gets the HTML for an image tag, using the Media Id.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <returns>Returns a HTML image tag from a Media Id.</returns>
        private string GetHtmlForImage(Media media)
        {
            // check that its not null
            if (media != null)
            {
                // get the img src
                var src = media.GetProperty<string>(Constants.Umbraco.Media.File);

                // check that the img src has a value
                if (!string.IsNullOrEmpty(src))
                {
                    // define the img tag
                    var img = "<img src=\"{0}\" alt=\"{1}\" height=\"{2}\" width=\"{3}\" />";

                    // get the height
                    var height = media.GetProperty<int>(Constants.Umbraco.Media.Height);
                    if (height <= 0)
                    {
                        height = (int)this.Height.Value;
                    }

                    // get the width
                    var width = media.GetProperty<int>(Constants.Umbraco.Media.Width);
                    if (width <= 0)
                    {
                        width = (int)this.Width.Value;
                    }

                    // if the default dimensions are less then zero...
                    if (height <= 0 && width <= 0)
                    {
                        // default the height & width to 100px;
                        height = 100;
                        width = 100;
                    }

                    // format the img tag
                    return string.Format(img, src, media.Text, height, width);
                }
            }

            // fall-back return an empty string
            return string.Empty;
        }