Developer forum

Forum » CMS - Standard features » Ecom product number not rendering on frontend

Ecom product number not rendering on frontend

Aditya Bante
Reply

Hi we have an Item based page and a ecom product catalog with detail view attached on its paragraph, and we would like to display the product number after the host name on the head of the page, for facebook's opengraph. The problem is, it renders everything except the product number on source code. please see below.

I have a variable which stores the path to product number
 @{ 
        var url = GetGlobalValue("Global:Request.Host");     
        var  productNumber = GetString("Ecom:Product.Number");
  } 

 <meta property="og:description" content='http://@url@productNumber ' />

and it renders everything but product number

<meta property="og:description" content='http://domain-name.net.dynamicweb-cms.com'>


what's wrong with it ?  any suggestions ? 

BR
Aditya Bante


Replies

 
Nicolai Høeg Pedersen
Reply
  • Is the product number field filled out for this product?
    • Make sure you do not confuse it with product id which is generated by DW
  • Are you inside a loop? Then you are missing the loop instance in front of you GetString method call
 
Aditya Bante
Reply
  • Yes the product number field is filled out for this product .
    • I also tried product name field, but it does not appear.
  • No, I am not inside the loop 
 
Nicolai Høeg Pedersen
Reply

Can you get any product data into the template?

Can you post the entire template please.

 
Aditya Bante
Reply

I am just trying to get product number and product image path on master template. 

please see the template below 

<!DOCTYPE html>
<html lang='@GetGlobalValue("Global:Area.Lang")'>
<head>
    <title></title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> 

    @if (!string.IsNullOrEmpty(GetString("Title")))
    {
    <meta property="og:title" content='@GetString("Title")' />
    }
    @if (!string.IsNullOrEmpty(GetString("Meta.Description")))
    {
    <meta property="og:description" content='@GetString("Meta.Description")' />
    }
    @{
        var url = GetGlobalValue("Global:Request.Host");
        var imagetag = GetString("Item.OpenGraphImage.Value");

         var productImage = string.Empty;

         if (!string.IsNullOrEmpty(GetString("Ecom:Product.ImageLarge.Clean")))
          {
              productImage = GetString("Ecom:Product.ImageLarge.Clean");
          }
          else
          {
              productImage = string.Format("/Files/Images/ecom/products/large/{0}.jpg", GetString("Ecom:Product.Number"));
          }
          var pno = GetString("Ecom:Product.ID");
    }
    @if (!string.IsNullOrEmpty(GetString("Item.OpenGraphImage")))
    {
        <meta property="og:image" content='http://@url/@imagetag' />
    }

    <meta property="og:image" content='http://@url/@productImage' />
    <meta property="og:image" content='http://@url/@pno' />

    
   

    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css' media="all" />
    <link href="/assets/stylesheets/layout.css" rel="stylesheet" media="all" type="text/css" />
    <link href="/assets/stylesheets/print.css" rel="stylesheet" media="print" type="text/css" />
    @RenderSnippet("StyleSheet")   
    <!--[if lt IE 9]>
      <script src="@GetString("Template:DesignBaseUrl")vendor/assets/javascript/lib/respondjs/respond.min.js" type="text/javascript"></script>
    <![endif]-->      
    <script data-main='@GetString("Template:DesignBaseUrl")assets/javascript/solutionset.init' src="/vendor/assets/javascript/lib/requirejs/require.min.js" type="text/javascript"></script>
 
</head>
@IncludeFile("Partials/Background.cshtml")
<body style="@(!string.IsNullOrEmpty(backgroundImage) ? backgroundImage : null)">  
 <div id="master-wrapper">    
        <div id="header-wrapper">
            <div id="header" class="container">               
                <div id="header-content" class="row">
                    <div id="header-logo" class="col-xs-12 col-sm-7 col-md-7 col-lg-8">
                        <a href="/"><img src='/..@GetString("Item.Area.Header_Logo")' alt="Logo" /></a>
                    </div>  
                </div>
            </div>   
        </div>

        <div id="navigation-wrapper">
            <div id="navigation" class="container">           
                @IncludeFile("Partials/NavigationMain.cshtml")            
            </div>
        </div>

        <div id="content-wrapper">
            @ContentPlaceholder()            
        </div>
        <div id="footer-wrapper">
            <div id="footer" class="container">             
                <div id="footer-content" class="row">                   
                    <div id="footer-copyright" class="col-xs-12">
                        @GetValue("Item.Area.Footer_Copyright")
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

 
Nicolai Høeg Pedersen
Reply

ok, so you have an item with a field which is product. Then the field is called something else.

Try running @TemplateTag("Product") to search for tags that contains Product information

 
Aditya Bante
Reply

No I don't have an Item with a field "Product" I meant the page where the Ecom catalog is attached is Item based page. I tried @TemplateTag("Product") it gives me few tags. Please see attached PNG. 

Tags.png
 
Nicolai Høeg Pedersen
Reply

Well, so you try to access produc data from your layout template, but have the product in a paragraph?

Then you have a context issue.

  • Layout template
    • Paragraph template
      • Module template (This is where your tags are available)

If you want to access the product data from your layout template, you can from your product template set the information on the ViewBag. So in your produc template do this: @ViewBag.ProductNumber = GetString("Ecom:Product.Number"); and in your Layout template take the information like this: @ViewBag.ProductNumber

You can also use Dynamicweb snippets: http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/General-tags/Snippet.aspx

 
Aditya Bante
Reply

When I insert that code into my ProductDetail template it gives me compieling Error "@ViewBag.ProductNumber = GetString("Ecom:Product.Number") "

Error compiling template "Designs/SolutionSet/eCom/Product/Product.cshtml"

Line 25: Invalid expression term '='

Line 25: ; expected 

 
Nicolai Høeg Pedersen
Reply

Then fix them!

 
Aditya Bante
Reply

It seems that @ character before ViewBag is giving this error , when I remove @ no compilling errors. but it does not render Product Number  when i put this @ViewBag.ProductNumber  in my master template it says it does not exist in the current context. 

 

 
Nicolai Høeg Pedersen
Reply

You might want to go read something about how razor and c# works...

In your paragraph template:

@{
    this.ViewBag.ProductNumber = GetValue("Ecom:Product.Number");
}

In your layout template, first add it to the bottom of your layout file:

<h1>@ViewBag.ProductNumber</h1>

But it might not work if you move it to the headers when I give some thought.

If not, use snippets instead.

 

You must be logged in to post in the forum