Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework : how to use "moreStyles" and "moreScripts"

In the file main.html, in default project created by Play!, there's this line :

#{get 'moreStyles' /}

I understand that if I need to add more styles, in my view script, I have to use

#{set tag:'value' /}

where tag should be moreStyles, but it seems worng to set the value to the full HTML <link> tag. And what happens if the view needs to add more styles, or scripts?

Thanks!

like image 383
Yanick Rochon Avatar asked Mar 11 '11 17:03

Yanick Rochon


2 Answers

you set more styles with:

#{set 'moreStyles'}
        #{stylesheet 'main.css' /}
#{/set}

like scripts:

#{set 'moreScripts'}
    #{script 'base64.js'/}
#{/set}
like image 143
Peter Avatar answered Nov 15 '22 12:11

Peter


simply using the #{set} tag will overwrite the previous values.

that is if you issue

#{set 'moreStyles'}xxx#{/set}

and then

#{set 'moreStyles'}yyy#{/set}

then

#{get 'moreStyles' /}

will only return yyy

in order to achieve what you want you have to

#{set 'moreStyles'}
    #{get 'moreStyles' /}
    #{stylesheet 'main.css' /}
#{/set}

and then the stylesheet main.css will be added to the previous value of morestyles

On a similar situation I ended up creating my own #{addStyle} tag

like image 36
opensas Avatar answered Nov 15 '22 12:11

opensas