2011-08-28 3 views
4

서식 파일에서 조건부 콘텐츠를 처리하는 기본 설정 방법은 무엇입니까?템플릿에서 조건부 콘텐츠를 처리하는 데 선호되는 리프트 방법은 무엇입니까?

"예를 들어 즐겨 찾기에 추가"버튼의 일반적인 구성을 상상해 봅시다. 즐겨 찾기에 없으면 추가 버튼을 클릭하십시오. 즐겨 찾기에 이미 있으면 제거 버튼이 있습니다. 이런 식으로 뭔가 :

<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> 

나는 (을 통해 중 결합 또는 CSS 변압기) 니펫에있는 확실한 방법이 표시되지 않는 조건에 해당하는 "즐겨 찾기"상태에 따라 다른 대 한 형태를 유지합니다.

Java/SpringMVC/JSP 배경에서 볼 수 있듯이 이것은 간단한 <c:choose> 문으로 해결할 수 있지만이 문제를 해결하는 데 많은 시간을 할애하여 완전히 완료 할 것이라고 가정 할 수 있습니다. 뒤로 ...

미리 감사드립니다.

+2

딜런이 말한 라인을 따라 가면서 명확하게 설명합니다. Lift의 템플릿에 논리가 없으면 모든 논리가 미리보기에 있습니다. 참고로이 기능을 사용하려면 일반 양식 대신 ajaxButton을 사용합니다. [github] (https://github.com/lift/framework/blob/master/web/webkit/)의 정의를 볼 수 있습니다. src/main/scala/net/liftweb/http/SHtml.scala). 마지막으로, [Lift 메일 링리스트] (http://groups.google.com/group/liftweb)에 질문을 게시하면 더 많은 답변을 얻을 수 있습니다. 대부분의 엘리베이터 개발자는 SO – fmpwizard

+0

에 오지 않습니다. @fmpwizard 생각합니다. 나는 나의 진짜 질문의 핵심 대신에 나의 모범과도 너무 거리낌이있다. 이 유형의 시나리오에서 실제로 수행 한 작업은 "리프트"방식입니다. 1. 모든 조건부 콘텐트를 템플릿에 넣은 다음 스 니펫에서 숨기거나 2. 컨테이너 HTML 요소를 사용하여 동적으로 조건부 HTML을 생성합니다. 단편. # 1은 나에게 맞는 느낌이지만, 나는 Lift tide에 반대하고 싶지 않다! (또한, 메일 링리스트에 대한 머리 감사합니다!) –

답변

6

내가 리프트 전문가로 주장하지 않습니다,하지만 날 여기에 합리적인 것 두 가지 옵션이있다 :

한 조각, 라 DoOrUndoFavorite이 있고, 그 안에 당신이 사용자의 즐겨 찾기 상태를 확인 할 니펫 하나 또는 다른 하나 (if(favorited){...} else{...}) 양식을 렌더링하십시오.

또는

은있는 그대로 당신의 조각을 유지하고, 각각의 코드를 렌더링 니펫을 내, 그 조각이 렌더링 안 경우 바인딩 용으로 NodeSeqNil을 반환합니다.

+0

고마워! 나는이 옵션들을 조사 할 것이다. –

1

내가 위에서 언급 한 리프트 메일 링리스트에서이 게시물 조건 html로 보여줍니다 생각 :

https://groups.google.com/forum/?fromgroups#!searchin/liftweb/conditional$20view/liftweb/CQG-wTx_qkc/pbD6PURwbksJ

관련 답변을보고 "쇼 인용 텍스트"를 클릭하여 확인을 여기에 인용, 그냥 경우 :

>On Oct 18, 10:05 pm, "Jason Anderson" < [email protected]> wrote: 
> Ah, that makes sense 
> 
> perhaps the simple/*.html pages in the lift example should be 
> changed to use this style of rendering rather than embedding the 
> templates in the snippet? 
> 
> it would also give you a chance to implement/test out that attribute 
> binding for links you mentioned in another reply 
> 
> On 10/18/07, David Pollak < [email protected]> wrote: 
> 
> 
> 
> > Jason, 
> 
> > <lift:snippet type="..."> 
> > <cond:true> 
> > <table> 
> > <tr><td><f:name/></td></tr> 
> > </table> 
> > </cond:true> 
> 
> > <cond:false> 
> > Hey, there are no users... sorry 
> > </cond:false> 
> > </lift:snippet> 
> 
> > You can represent both cases (or even multiple cases) in the XHTML 
> > and let the snippet decide which subsection of the XHTML to use. 
> > Given Scala's amazing XML handling capaibilities, it's a single line 
> > of Scala code to select the code block: 
> 
> > val trueBlock = (xhtml \ "true").filter(_.prefix == "cond").headOr 
> > (<span>Template not defined</span>) 
> 
> > It does make the template look a little ugly, but no worse than an 
> > ERB or JSP block looks. 
> 
> > Also, the <cond:.../> is a convention I've been using, but you can 
> > use any tags (e.g., <users:some> & <users:none>) 
> 
> > Thanks, 
> 
> > David* 
관련 문제