0

Is it possible to add a static block within .html()? I'm trying to switch between static blocks if window width is greater than 1024px.

$(window).ready(function() {
    var ver = $(window).width();  
    if (ver > 1024) {
$("div.homeload").html('{{block type="cms/block" block_id="xxx"}}');
  } else {
 $("div.homeload").html('{{block type="cms/block" block_id="xxxv2"}}');
  }

$(window).resize(function() {
    var ver = $(window).width();
    if (ver > 1024) {
$("div.homeload").html('{{block type="cms/block" block_id="xxx"}}');
   } else {
$("div.homeload").html('{{block type="cms/block" block_id="xxxv2"}}');
  }
});            
});
Billy
  • 126
  • 1
  • 10
  • As long as it is within a template, the contents should be displayed properly. – Brian Jan 15 '18 at 05:27
  • Thanks for the prompt reply. The static blocks have "TEST" and "TEST V2". Neither block displays. I even switched out the static blocks to one that I use on other pages, that doesn't display either. – Billy Jan 15 '18 at 05:35
  • If this does not work, you can insert javascript directly into the blocks – Brian Jan 15 '18 at 05:46
  • Because you can embed blocks within other blocks, you should be able to create a new block using the code above, and embed that instead. – Brian Jan 15 '18 at 05:52
  • That's not working either. I removed the code above from the CMS page placed it in to a static block(TESTCALL) and tried to put {{block type="cms/block" block_id="TESTCALL"}} on the CMS page. That did not work either. Think I'm going to have to approach this from a different angle. Thank you for prompt responses and your suggestions. – Billy Jan 15 '18 at 06:31
  • I take back what I said. It's semi working. The static block is being loaded in the .html('THE CODE IS SHOWING UP HERE') but it is not showing up within
    .
    – Billy Jan 15 '18 at 06:56
  • Instead of window.ready, which has unspecified behavior, you can use the jquery document.load shorthand, which is simply `$(function() { // your code here });` This will ensure that the function is executed only when all resources have been loaded. – Brian Jan 15 '18 at 14:39
  • have to got the ansswer? – faizanbeg Jan 16 '18 at 06:04
  • Not yet. I used a different approach to do what I needed to do. I'm going to continue to see if I can get this to work somehow. If I cannot I will accept Mr. Singh's answer as the acceptable answer. – Billy Jan 16 '18 at 07:32

0 Answers0