Using variables in Jade with node.js (substring in jade)

Another funny issue I ran into: apparently jquery can not find elements by ID (#) if the ID string starts with a hashtag (#). In my case, I was using IDs generated from twitter hashtags, and as you know hashtags start with #

So, using $(‘p##myhashtag’).html() did not work. What I could do, is to change the ID of the element and remove the # from the ID. But how do you do it with jade?

That’s when variable support in jade comes in handy! You can manipulate your data right in jade templates using regular javascript. Here’s a snippet that removes hashtag (first character in your string):

    - var st = hashtag
    - var len = st.length
    - var myst = st.substr(1,len)
    p(id=myst)
Advertisements

One thought on “Using variables in Jade with node.js (substring in jade)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s