How can I call fragments from different packages in an elevator?

I am trying to call one of two snippet methods with the same name and the same class, but these fragments are in different packages. Here is a sample code:

Fragment 1:

package v1.site.snippet class TestSnippet { def test = { println("printed from v1") } } 

Fragment 2:

 package v2.site.snippet class TestSnippet { def test = { println("printed from v2") } } 

index.html

 <div class="lift:TestSnippet.test"></div> 

So, how do I tell index.html which TestSnippet.test to call? Both packages have been added to my Boot.scala.

+4
source share
1 answer

One option:

 LiftRules.snippetDispatch.append { case "V1TestSnippet" => new v1.site.snippet.TestSnippet case "V2TestSnippet" => new v2.site.snippet.TestSnippet } 

Then your fragments should inherit DispatchSnippet and define def dispatch = { case "test" => test _ } , etc. Then you call fragments from the template like V1TestSnippet or V2TestSnippet .

Alternatively, something like

 LiftRules.snippets.append { case "V1TestSnippet"::"test"::Nil => (new v1.site.snippet.TestSnippet).test _ case "V2TestSnippet"::"test"::Nil => (new v2.site.snippet.TestSnippet).test _ } 

I believe List is the name of the fragment in the template, broken into dots.

+3
source

Source: https://habr.com/ru/post/1479808/


All Articles