Check a boolean in the view

I know i probably shouldnt be doing this and maybe should move this to a
helper or to the controller but how do i set a flag in the view.

So for the code below im checking if x=y and if so then render a partial
and set a flag called check = true.

in the else then i want to output some text and then reset the boolean
back to false.

Can this be done? Whats the best way to this?

<% @contents.each do |content| %>
<% if contentpos.pos == content.pos %>
<%= render :partial => ‘content’, :object => content %>
<% check = true %>
<% else %>
<% if check == true %>

True


<% check = false %>
<% end %>
<% end %>
<% end %>

Fixed it:

<% bcheck = false %>
<% @contents.each do |content| %>
    <% if contentpos.pos == content.pos %>
        <%= render :partial => 'content', :object => content %>
        <% bcheck = true %>
   <% else %>
       <% if bcheck == true %>
            <br/>
            <% bcheck = false %>
        <% end %>
    <% end %>
<% end %>