Hi,

I want to know how can I add HTML code in the block for Drupal 7. Is there any module which allow me to add HTML code in the block?

Thank you.

Comments

aspilicious’s picture

just change the input filter to full html? It's in core no module needed

Hi, I'm too precious to answer right now. Please email me later.

Codenext’s picture

Hi, your information is nice, i found this post while searching "Adding HTML, JS and CSS code in drupal block. just need some more details this aspect. I have made a code using HTML, JS and CSS. In normal scenario the CSS part and JS will go in "" section. But do we need to write the standard format of HTML while writing code in full HTML mode in the block? So, how can we add all there section during in the text box (full html mode)?

For example,

<!DOCTYPE html>
<head>
    <style>
         /*CSS section/
    </style>
    <script>
        /*JS section/
     </script>
</head>

<body>
       /*Content section/
</body>

</html>

Now, how can write the above code that text-box(full html enabled)? Do i have to write entire code as described in the above format?
Thanks in advance.

NOTE: By error i have posted same message as comment.

FOXs-M’s picture

...

seanray’s picture

You can just add HTML code in your block, this is supported by Drupal by default. You might meet a html filter issue, which could be resolved by add more html elements in admin/config/content/formats

rubensargsyan’s picture

aspilicious and seanray, thank you very much for your help.

Here is how to do it in more details for them who new in Drupal:

Go to Structure => Blocks => Add block, set "Text format" to "Full HTML" and write the html code into the textarea "Block body". Don't forget to fill "Block description" field, because it is required too. :)

Thank you again.

dalbabudavid’s picture

Please, is there a way to add html code into drupal block? I being try to create marquee text in my drupal project.. please, help

Codenext’s picture

Hi, your information is nice, i found this post while searching "Adding HTML, JS and CSS code in drupal block. just need some more details this aspect. I have made a code using HTML, JS and CSS. In normal scenario the CSS part and JS will go in "" section. But do we need to write the standard format of HTML while writing code in full HTML mode in the block? So, how can we add all there section during in the text box (full html mode)?

For example,

<!DOCTYPE html>
<head>
    <style>
         /*CSS section/
    </style>
    <script>
        /*JS section/
     </script>
</head>

<body>
       /*Content section/
</body>

</html>

Now, how can write the above code that text-box(full html enabled)? Do i have to write entire code as described in the above format?

Jaypan’s picture

Blocks are a section of an HTML page, not the whole page. You are trying to build a whole page in the block - this cannot be done.

Codenext’s picture

Dear Jaypan, Thank for the answer. I am also aware that we can not put whole page in block and it is not mentioned in my question that i am going to put whole code in block. But my question's core is since in "HTML" code we generally put JS and CSS part in the "head" section. Now I can not put that "head /head" in the block section so, what is the standard practice to put JS and CSS along with HTML? Thanks

uzmaabdulrasheed1@gmail.com’s picture

Dear Codenext,

You can add HTML in block without "head","script","style","link","body","html" and "meta". You would just need to add specific html for that block and the rest of the layout html will render from page.tpl.php, for CSS and JS you should add it in theme's css and js file.

Let me know if you have further questions.

Thanks
Uzma Abdul Rasheed

Codenext’s picture

Hi, I leaned that now, at that time I was in very initial stage in Drupal learning. Later I asked questions on drupal answer/stakexchangeand got the answers. Now I am quite comfortable with that. Thanks for providing answer though, very appreciated.

harismuzaffer’s picture

There are already many posts on the html issue.. pls tell me how can i actually insert html code in any of my pages, basic page or an article. for example i want to use hyperlink tag or strong tag, it doesnt work when i view the page...

VM’s picture

That indicates that you aren't using the proper text format or have the tags needed set as allowed. Please review the documentation regarding text formats.

harismuzaffer’s picture

i hv enabled full html and im acting as adminstrator.. do i need anything else.. ?.. again when i enabe php format for the same page everything goes fine.. php and html both work... but setting full html doesnt seem to work.

VM’s picture

edit the config of the of the text format. Have you check which tags are allowed? FULL HTML is only a concept. It doesn't magically allow ALL tags to be used. Again, please read the text format documentation.

Codenext’s picture

@harismuzaffer

First let me explain about the text formats which is located at Administration->Configuration->Content Authoring->Text Format

Now, if you read the following Link, there is a some issue with the drupal text format, Normally we select the text format when we create the content type, but that selection will not reflect in your final saved content type, it will show the all the options.

Now, if you click the Administration->Configuration->Content Authoring->Text Format, you will see the following order,

- Filtered HTML
- Full HTML
- Plain Text

so, what happens, whichever is first works as default this is by default cinfiguration, so if above case everywhere default will be Filtered. Now what you do change the order, as shown below, so for you it will always be full HTML and for the visitors it will always be filtered HTML as visitors do not have access of administration, so this part is set.

- Full HTML
- Filtered HTML
- Plain Text

Hope you get it till now.

Now, other check open the Administration->Configuration->Content Authoring->Text Format->Full HTML, and you should see following setting, which is by default,

Roles
(Not-tick) anonymous user
(Not-tick) authenticated user 
(tick) administrator
Enabled Filters
(Not-tick) - Limit allowed HTML tags
(Not-tick) - Display any HTML as plain text
(tick) - Convert line breaks into HTML (i.e. <br> and <p>)
(tick) - Convert URLs into links
(tick) - Correct faulty and chopped off HTML

Make sure the "Limit allowed HTML tags" is not ticked.

So, if till this OK, your text format should work properly.

Now, Are you using CKeditor along with that? if no, not a issue, but if yes we need to check the config of CKEditor also, as CKEditor also chop off the HTML tags.

Now, you write your HTML code in the 'body' area if your HTML code is correct it should be shown properly on the final webpage. If not write the comment what is the issue?