Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:38:16+00:00 2026-06-06T14:38:16+00:00

I want to generate html like, <label for=’field’> Label Text <span class=’span1′> Some Text

  • 0

I want to generate html like,

<label for='field'>
  Label Text
  <span class='span1'> Some Text 1 </span>
  <span class='span2'> Some Text 2 </span>
  ...
</label>

I want a call a helper such as,

label_for 'field', :label => 'Label Text', :type1 => 'Some Text 1', :type2 => 'Some Text 2'

For which I tried to do something like,

 content_tag(:label, opts[:label], :for => field_name) do
   ['span1', 'span2'].map { |i| 
     content_tag(:span, opts[i], :class => i) if opts[i] }.compact.joins('+').html_safe
   }
  end

But this does not work (of course).

[‘span1’, ‘span2’] array is fixed and the user has the option of choosing to display as many spans as needed.

How can I solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:38:17+00:00Added an answer on June 6, 2026 at 2:38 pm

    Why not something like this?

    def special_label_for(field_name, label_text, span_array)
      content_tag "label", :for => field_name do
        concat label_text
        span_array.each_with_index do |span_content, index|
          concat content_tag("span", span_content, :class => "span" + index.to_s)
        end
      end
    end
    
    special_label_for :user_name, "User Name", ["This is the first Span", "And this is the second Span", "Can also have a third span", "Or as many spans as you like"]
    

    Haven’t tested this code, may need to add/remove the concat or an html_safe to get it rendering properly in your view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to export some data i want to be able to generate an html output.
I want to generate PDF from a PHP file that includes HTML controls like
I want to auto-generate a HTML table from some custom data. One of the
I'd like to know if this code... echo $this->Html->link( <h3>test</h3>.$this->Html->image(image.jpg).<p>Some text</p>, /link, array('escape' =>
I want to generate html content based on a result returned by http url.
I want to conditionally output HTML to generate a page, so what's the easiest
Let's say I have a class of 30 students and want generate every possible
I want to generate a HTML-Documentation for my Javascript code. The comments in my
This is my current problem. I want to generate a HTML page, which contains
I want to generate HTML pages with rst2html, using my own templates. these templates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.