Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set html / body tag attributes in Meteor.js?

Tags:

meteor

I need to set attributes on the html tag or alternatively the body tag of the document in a Meteor.js application.

Specifically I want to have <html dir="rtl"> or <body dir="rtl">..

Trying the latter, I receive the console message:

While building the application:
client/views/layout/layout.html:7: Attributes on <body> not supported

=> Your application has errors. Waiting for file change.

So how do you do this?

like image 922
alnafie Avatar asked Jan 14 '14 08:01

alnafie


People also ask

Where do you put body tags in HTML?

HTML <body> tag defines the main content of an HTML document which displays on the browser. It can contain text content, paragraphs, headings, images, tables, links, videos, etc. The <body> must be the second element after the <head> tag or it should be placed between </head> and </html> tags.

How many attributes are there in body tag?

Remember the <body> tag from the first page, which everything visible on your page goes into? That is the tag we'll be adding to in this, as it's been left untouched up until now. There are 7 attributes to be added here, and they all change how your page looks.


2 Answers

You have to inject them on start-up in your client-side Javascript:

Meteor.startup(function() {
   $('html').attr('dir', 'rtl');
});

UPDATE

Note that you can now set attributes in-line for body tags, and they'll be concatenated by Meteor in the same way as the contents of the body tag:

<body data-atttribute="foobar"></body>

You can have multiple different body tags, and they'll get combined, so the above will just add a single attribute to your existing body, rather than replacing it.

To the best of my knowledge, HTML tag attributes still need to be set via Javascript.

like image 194
richsilv Avatar answered Nov 10 '22 07:11

richsilv


Attributes for HTML tag can be set on startup by using WebApp.addHtmlAttributeHook function. Here is an example:

Meteor.startup(function() {
    WebApp.addHtmlAttributeHook(function() {
        return {
            "dir": "rtl"
        }
    })
});

Make sure you call this on server, not client.

like image 25
Turgut Sarıçam Avatar answered Nov 10 '22 09:11

Turgut Sarıçam