Question

I only want to output one anchor here. If the current_page is in the array I get two (.html and -nf.html). If it is not in the array I get as many anchors as there are items in the array.

I am using StaticMatic.

- if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

    // loop through the pre-flash array and if current page matches, add -nf
    - page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
    - page_options[:pre_flash].each do |each_string|

        - if current_page.include? each_string
            %li 
                %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                    Next
        - else
            %li
                %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
                    Next
Was it helpful?

Solution

unless current_page.include? the_string

Edit:

You could break the each-loop if you want your first finding to be the only one. But now this looks a little bit weird, because you are iterating over an array and breaking after the first element no matter what happens. Am I addressing your problem at all?

options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
page_options[:pre_flash].each do |each_string|
  if current_page.include? each_string
    %li 
    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
    # This is the last ancor
    break
  else
    %li 
    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
    # This is the last ancor
    break
  end
end

OTHER TIPS

Okay, so I think we're checking that none of page_options[:current_index] are substrings of current_page.

if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

found_item = false

// loop through the pre-flash array and if current page matches, add -nf
- page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
- page_options[:pre_flash].each do |each_string|

    - if current_page.include? each_string
            found_item = true
            %li 
                    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                            Next

# do whatever you need to get out of the staticmatic block...

    - if !found_item

            %li
                    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }

Sorry - I misunderstood what you were doing... thought you were doing an include? on an array but it was a string... :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top