Reputation: 35
I am using a theme that i bout on themeforest for my rails project where developers used custom data tags to load background image.Code looks like below.
<div class="swiper-slide fit slide-1" data-pages-bg-image="assets/images/banner_1.jpg">
whats the syntax to use data attribute inside div tag? i am using erb as my template engine
Upvotes: 1
Views: 3647
Reputation: 405
<div class="swiper-slide fit slide-1" data-pages-bg-image="assets/images/banner_1.jpg">
content_tag
if your ruby version greater than 2.3
<%= content_tag(:div, "blah blah", 'data-pages-bg-image' => "asets/images/banner_1.jpg", class: "swiper-slide fit slide-1") %>
or not (1.9 etc)
<%= content_tag(:div, 'blah blah', "data-pages-bg-image" => "assets/images/banner_1.jpg" :class => "swiper-slide fit slide-1") %>
example)
<section id="tabs">
<ul>
<li><%= content_tag(:a, "text", :href=> "#", :data => { :flights => "6" } ) %></li>
<li><%= content_tag(:a, "text", :href=> "#", :data => { :flights => "5" } ) %></li>
<li><%= content_tag(:a, "text", :href=> "#", :data => { :flights => "5" } ) %></li>
</ul>
</section>
Upvotes: 2
Reputation: 1
data is not a property if div.
You can use attr.data with div. [data-pages-bg-image]=
Upvotes: -1
Reputation: 3126
If you want to set data attributes to your div in your erb with some value from your database, you can do it like this.
<div class="swiper-slide fit slide-1" data-pages-bg-image="<%= @item.bg_image %>">
#@item.bg_image is an example, you should put your variable there
Upvotes: 1