4

Im noob in Drupal and I don't know how can I put the FB code for display the last post in a block. I'd create a block with php code text format, but doesn't work, the block does not render the code. This is the code from FB, if I put it into a plain html file it works fine

<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/sdk.js#xfbml=1&version=v2.7";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-page" data-href="https://www.facebook.com/mysupersite" data-tabs="timeline" data-width="320" data-height="450" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"></div>

How can I put this into a block? I'd created a block--fb.tpl.php cloning the block.tpl.php and pasted the code but this doesn't work either. This is for not use the FB module because I should create an app and FB request my data and I don't want an app, just render the last post of the profile can someone give me some gide with this? Thank you so much for your help

6

An alternative way if you love coding...

You can create module for fb add block.

module name : custom

function custom_block_info() {
  $blocks = array();
  $blocks['add_fb'] = array(
    'info' => t('Add fb'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implement hook_block_view().
 */
function custom_block_view($delta = '') {
  $block = array();
  switch ($delta) {
      case 'add_fb':      
        $block['content'] = t('<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/sdk.js#xfbml=1&version=v2.7";
  fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>

<div class="fb-page" data-href="https://www.facebook.com/mysupersite" data-tabs="timeline" data-width="320" data-height="450" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"></div>');
      break;
  }
  return $block;
}

Now you can see a block on "admin/structure/block" named as "Add fb". Place the block where ever you want.

  • Thank you so much dude! It works fine! I'd create the module and in Chrome it works fine, but in FF doesn't work, but is a step to get the FB working on my site. Thanks again! – bug273 Sep 15 '16 at 13:26
  • 2
    this solution will work but it's not straightforward and usual method for putting some html markup in block content ;) – Yusef Sep 15 '16 at 20:07
6

if you using ckeditor firstPut your block text format on FULL HTML then click on soruce and finally paste your markups there.

enter image description here

  • I already try with full html. When I try with full html text format I get the code in plain text in the right sidebar. I have ckeditor activated as text editor and when I paste the code in the block ckeditor renders the code in plain text :( – bug273 Sep 15 '16 at 12:10
  • 1
    @bug273 simple solution first put ckeditor in source view then paste your markup there, another solution is disable load ckeditor for this block ( or for block edition ) page. – Yusef Sep 15 '16 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.