Frage

Ich möchte nur die Ausgabe eines Dübels hier. Wenn die current_page im Array bekomme ich zwei (.html und -nf.html). Wenn es nicht im Array bekomme ich so viele Anker, da es Elemente im Array ist.

Ich bin mit 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
War es hilfreich?

Lösung

unless current_page.include? the_string

Edit:
Sie könnten die jede Schleife brechen, wenn Sie Ihre erste Erkenntnis der einzige sein wollen. Aber jetzt sieht es ein wenig seltsam, weil Sie über ein Array iterieren und bricht nach dem ersten Elemente, egal was passiert. Bin ich Ihr Problem überhaupt Adressierung?

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

Andere Tipps

Okay, so dass ich denke, wir überprüfen, dass keine von page_options [: CURRENT_INDEX]. Sind Teil von 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 - ich falsch verstanden, was Sie taten ... haben Sie eine Include taten? auf einem Array, aber es war ein String ...: -)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top