开发者

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?

Tha开发者_高级运维nks!


you set more styles with:

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

like scripts:

#{set 'moreScripts'}
    #{script 'base64.js'/}
#{/set}


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


#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/ui-lightness/jquery-ui.css" charset="${_response_encoding}"/>
#{/set} 
#{set 'moreScripts'}
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript" charset="${_response_encoding}"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/i18n/jquery.ui.datepicker-zh-CN.js" type="text/javascript" charset="${_response_encoding}"></script>
<script language="javascript">
    $(document).ready(function() {
        $('.datepicker').datepicker();
    });
</script>
#{/set}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜