Get Scriptlet HeaderData so that it parses nVelocity?

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
User avatar
gjaros
AbleCommerce Partner
AbleCommerce Partner
Posts: 1717
Joined: Tue Feb 24, 2004 2:20 pm
Location: Illinois
Contact:

Get Scriptlet HeaderData so that it parses nVelocity?

Post by gjaros » Wed Feb 01, 2012 3:16 pm

Is it possible to get the HeaderData in a scriptlet to parse nVelocity code? I'd like to put a meta tag on pages that contains the URL of the product image for use with the Facebook Open Graph tags. Basically, I'd like this to display in the header:

Code: Select all

#if($Product.ImageUrl != '')
<meta property="og:image" content="${Page.ResolveUrl(Product.ImageUrl)}"/>
#else
<meta property="og:image" content="Store_Logo.png"/>
#end
But it just outputs exactly what is entered without parsing the nVelocity...

Thanks!
Image
Image

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: Get Scriptlet HeaderData so that it parses nVelocity?

Post by david-ebt » Thu Feb 02, 2012 10:58 am

I'm not sure if nVelocity has access to the header. Here's a simple conlib that will add many of the Facebook Open Graph tags. I've called it FaceBookTags.ascx and then call it in the Show Product scriptlet. If you have thumbnail images, you might want to change the ImageUrl to ThumbnailUrl - it should display better on Facebook.

Code: Select all

<%@ Control Language="C#" ClassName="FaceBookTags" %>

<script runat="server">

    private string _newTitle;
    public string NewTitle 
    {
        get { return (String.IsNullOrEmpty(_newTitle)) ? Page.Title : _newTitle; }
        set { _newTitle = value; }
    }

    protected void Page_Load( object sender, EventArgs e )
    {
        int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        Product _Product = ProductDataSource.Load(_ProductId);

        if (_Product != null)
        {
            HtmlMeta ogImage = new HtmlMeta();
            HtmlMeta ogUrl = new HtmlMeta();
            HtmlMeta ogTitle = new HtmlMeta();
            HtmlMeta ogSite = new HtmlMeta();

            ogImage.Name = "og:image";
            ogUrl.Name = "og:url";
            ogTitle.Name = "og:title";
            ogSite.Name = "og:site_name";

            if (!string.IsNullOrEmpty(_Product.ImageUrl))
                ogImage.Content = _Product.ImageUrl;
            else
                ogImage.Content = "storelogo.png";
            
            ogUrl.Content = Token.Instance.Store.StoreUrl + _Product.NavigateUrl.Replace("~/",null);
            ogTitle.Content = _Product.Name;
            ogSite.Content = Token.Instance.Store.Name;

            Page.Header.Controls.Add(ogImage);
            Page.Header.Controls.Add(ogUrl);
            Page.Header.Controls.Add(ogTitle);
            Page.Header.Controls.Add(ogSite);
        }
    }

</script>
There are other open graph tags. Another that is often useful is the og:type which tells what it is you're talking about, something like "product".

Here's a link to a page that describes many of the other tags:
http://ogp.me/
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

User avatar
gjaros
AbleCommerce Partner
AbleCommerce Partner
Posts: 1717
Joined: Tue Feb 24, 2004 2:20 pm
Location: Illinois
Contact:

Re: Get Scriptlet HeaderData so that it parses nVelocity?

Post by gjaros » Fri Feb 03, 2012 7:31 pm

Thanks! That worked great!
Image
Image

Post Reply