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

  • Home
  • SEARCH
  • 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 6003607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:44+00:00 2026-05-23T01:08:44+00:00

In my Rails template, I’d like to accomplish final HTML to this effect using

  • 0

In my Rails template, I’d like to accomplish final HTML to this effect using HAML:

I will first <a href="http://example.com">link somewhere</a>, then render this half of the sentence if a condition is met

The template that comes close:

I will first
= link_to 'link somewhere', 'http://example.com'
- if @condition
  , then render this half of the sentence if a condition is met

You may, however, note that this produces a space between the link and the comma. Is there any practical way to avoid this whitespace? I know there’s syntax to remove whitespace around tags, but can this same syntax be applied to just text? I really don’t like the solution of extra markup to accomplish this.

  • 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-05-23T01:08:45+00:00Added an answer on May 23, 2026 at 1:08 am

    A better way to do this has been introduced via Haml’s helpers:

    surround

    = surround '(', ')' do
      %a{:href => "food"} chicken
    

    Produces:

    (<a href='food'>chicken</a>)
    

    succeed:

    click
    = succeed '.' do
      %a{:href=>"thing"} here
    

    Produces:

    click
    <a href='thing'>here</a>.
    

    precede:

    = precede '*' do
      %span.small Not really
    

    Produces:

    *<span class='small'>Not really</span>
    

    To answer the original question:

    I will first
    = succeed ',' do
      = link_to 'link somewhere', 'http://example.com'
    - if @condition
      then render this half of the sentence if a condition is met
    

    Produces:

    I will first
    <a href="http://example.com">link somewhere</a>,
    then render this half of the sentence if a condition is met
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Rails 3. I want to display generated html fragment inside erb template
I am using authlogic-connect in Rails. I am using a simple haml template where
I am using authlogic-connect in Rails. I am using a simple haml template where
If you are using HAML and SASS in your Rails application, then any templates
I've been using Netbeans for Rails and like it a lot, considering how little
If you use haml as rails view template, you can write portion of your
I have a _form.html.erb partial that comes from the standard rails 3 template for
i've started using rails 3 beta3 and I have see that the @template variable
I am trying to create a rails template that will add code to files
I have a rails template (.rhtml file) generating a Javascript object. It looks something

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.