How To Add Iframe Tag In Django CMS Placeholder

If you ever tried to add iframe tag in  djangocms placeholder , you  will notice that it will not work  as you  expect. DjangoCMS will convert iframe  tag  in other format and it will be shown as text

 

Add Iframe Tag In Django CM

ifraem django cms

 

This tutorial explains how to  trick djangoCMS with jQuery and add iframe in placeholder.  In your base.html , before </body> tag add

 

$(document).ready(function($)
          {
             var pathname = window.location.pathname;
            
               var facebook='<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdjangotutsme.com%2F'+pathname+'%2F&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>'
             $( "#facebook" ).html(facebook);

   
          });

 

$( "#facebook" ).html(facebook); will add variable called facebook in div tag with id = "facebook" ,

variable pathname contain current URL, for example if you open  http://www.djangotutsme.com/how-add-iframe-tag-django-cms-placeholder/ , in variable pathname will be stored how-add-iframe-tag-django-cms-placeholder/

So now got to Source mode and add div with id "facebook", and you'll set upp facebook like box

iframe django

and you'll get facebook like box as shown below

 

 

You can use the same technique to add any iframe tag.

 

$(document).ready(function($)
          {
           
            
               var variable1='<iframe src="URL1"></iframe>';
             $( "#iframe1" ).html(variable1);

            var variable2='<iframe src="URL1"></iframe>';
             $( "#iframe2" ).html(variable2);

            // ...you can add iframe tag as many you want

 

   
          });

Then in placeholder add div tag with id-s which you specify in jQuery , for example above ids are  "iframe1" , "iframe2"

 

email@djangotutsme.com Dec. 22, 2014, 7:04 a.m.