Lift Web : Basics of using snippets for a beginner

If you are a beginner of using Lift web framework, then it will help you a lot for understanding how to play with views and snippets.

Here, I am explaining some basic use of snippets.
1. Replace id of a html attribute , if class is given.

2. Replace id of a html attribute , if id is given

Use # for id and .(dot) for class
3. Add a style to html element, if class is given

4. Replace content of particular id

5. Replace value of particular element

6. How to use Javascript alert

7. Ajax click event on button.
a) Here “Create” will be text of Button.

b) No button text here

8. Get value of Text box

Here 1st argument will set the text box default value and 2nd argument which is a function will get textbox value and assign it to text variable.

9. Get value of TextArea

Here 1st argument will set the TextArea default value and 2nd argument which is a function will get TextArea value and assign it to text variable.

10. If you want to show any message from snippets then use it as :

Here S.error() is used for displaying error message and S.notice() is used to display notice messgae.
Messages will be displayed where above “div” tag will be defined.

11. Set full html content to given id.

SetHtml() takes 2 arguments. one is id where html content to replace and second is scala NodeSeq.
12. How to write javascript code in snippets :

Whatever we write in between script tag, we can write directly that into JsRaw() method

Written by 

Rishi is a Lead Consultant, with experience of more than 7 years. Rishi is product focused developer who loves developing both front-end user interfaces and scalable back-end infrastructure. He is a good team player, quick learner and a humble person. He has good time management skills, aimed to give best results and fully dedicated towards his work & responsibilities. He is able to work as individual and as well as in team. He loves to share his knowledge, therefore he often writes technical blogs.

1 thought on “Lift Web : Basics of using snippets for a beginner

Leave a Reply

%d bloggers like this: