开发者

Adding comments mod into Smarty Template PHP site

开发者 https://www.devze.com 2023-04-07 00:15 出处:网络
My site is built around X-Cart 4.2.3, which is built around Smarty Templates. I am trying to figure out a way to add Facebook Comments to my dynamic product pages (https://developers.facebook.com/docs

My site is built around X-Cart 4.2.3, which is built around Smarty Templates. I am trying to figure out a way to add Facebook Comments to my dynamic product pages (https://developers.facebook.com/docs/reference/plugins/comments/). These have to have unique URLs for each product page. I found an X-cart wiki on how to add the LIKE button, which I did successfully. This was the code for the LIKE button:

 <iframe src="//www.facebook.com/plugins/like.php?href={$php_url.url|escape:"url"}&amp;send=false&amp;layout=standard&amp;width=350&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:80px;" allowTransparency="true"></iframe>

The code above is exactly the same as what Facebook's tool spits out, except for the dynamic URL variable: {$php_url.url|escape:"url"} I wanted to basically repeat the same process for the COMMENTS module, but that one is strictly xfbml, rather than iframe, which creates two problems: Problem 1: even if I paste the xfbml code verbatim into my product.tpl template, I can't get the comments mod to show up on the front end of the store. Same thing happens with the xfbml code of the LIKE button. Only iframe seems to work. Problem 2: even if I solve the first problem, how to I utilize the URL variable in the fb tag, since it has quotes around the URL? Any thoughts? Below is the standard comments code:

开发者_运维知识库
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<fb:comments href="example.com" num_posts="10" width="500"></fb:comments>


I think you want the Smart Literal tag. You should turn if on/off inside JS and may be effecting your URL issue too. You can see find details here:

http://www.smarty.net/docsv2/en/language.function.literal


Colin, brilliant call on your part. You solved the problem! This code actually works perfectly:

<div id="fb-root"></div>

{literal}
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{/literal}
<fb:comments href="{$php_url.url|escape:"url"}" num_posts="10" width="730"></fb:comments>

One small problem... the comment mod sometimes appears at the bottom of articles, and sometimes not. I've noticed this only in the latest version of IE. It's as if sometimes the pages load fully, but sometimes they don't. Could be a problem on my end, I hope. If you have a moment, take a look at these articles: http://horrorunlimited.com/Fresh-Blood-and-Crumpets/

Dima

0

精彩评论

暂无评论...
验证码 换一张
取 消