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 6376643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:46:17+00:00 2026-05-25T01:46:17+00:00

What is the preferred Lift way to handle conditional content in a template? As

  • 0

What is the preferred Lift way to handle conditional content in a template?

As a concrete example, let’s imagine the common construct of an “Add to My Favorites” type button. If not in your favorites, there is a button to click to add it. If already in your favorites, there is a button to remove it. Something like this:

<div class="lift:MySnippet">

  <!-- other stuff -->

  <div class="favorite">
    <form id="doFavorite" class="lift:MySnippet.favorite?form=post">
      <input type="submit" value="Add to Favorites" />
    </form>
    <form id="doUnfavorite" class="lift:MySnippet.unfavorite?form=post">
      <input type="submit" value="Remove from favorites" />
    </form>
  </div>

  <!-- other stuff -->

</div>

I don’t see an obvious way in the snippet (via either binding or CSS transformers) to conditionally keep one form vs the other based on the appropriate “favorited” state.

Coming from a Java/SpringMVC/JSP background, this would be solved with a simple <c:choose> statement, but with as much time as I’ve spent trying to figure this out, I can only assume I am going about this completely backwards…

Thanks in advance, Lift gurus!

  • 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-25T01:46:17+00:00Added an answer on May 25, 2026 at 1:46 am

    I don’t claim to be a lift guru, but here’s two options that seem reasonable to me:

    Have one snippet, a la DoOrUndoFavorite, and within that snippet you would check the favorited state for the user and render one or the other (if(favorited){...} else{...}) form.

    or

    Keep your snippets as they are, and within each snippet’s render code, return a Nil as the NodeSeq for your binding if that snippet should not render.

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

Sidebar

Related Questions

What is a preferred way to store recurring time windows? For example. If I
Is there a preferred way to handle animation when using Flex -- For instance,
What is the preferred way to work with Singleton class in multithreaded environment? Suppose
What is the preferred way of deploying a compojure/sinatra applications? I have multiple sites
What is the preferred way to build application gui components tree? Instantiate all components
Which is the preferred way of defining class properties in Python and why? Is
What is the preferred way to store styles very specific to one single dom
What is the preferred method of using std::rel_ops to add the full set of
Which is the preferred/recommended way of handling events in .NET: this.Load += new EventHandler(Form1_Load);
What is the most preferred and easiest way to do pagination in ASP.NET MVC?

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.