Custom javascript sitemesh per page

I am using sitemesh for the spring site. The problem is that I have javascript that I want it to run in the onload event of only one specific page using jquery $(function() { ... }), and not on every page.

I included jquery.js at the bottom of my decorator, after the body. So, if I try to include a tag <script>in the body of my decorated page, the script will not be executed, because after that jquery will be loaded! I know that I could include jquery.js in the header of my decorator, so that it will be before the user script on the decorated page, but I do not really like this solution, since it will contain javascritp at the beginning of my page,

So, I would like to have something like a placeholder in my sitemesh decorator, where the custom text will be placed from my decorated page (since you can understand that I come from the world of django: p). Is it possible? Do you suggest anything else, or should I just put jquery.js in the header and do with it?

+4
source share
1 answer

To answer my question, after some searching, I found the following solution:

I added the following to the end of my decorator page (after jquery.js is included)

<decorator: getProperty property = "page.local_script"> </ decorator: getProperty>

I also added the following

<content tag = "local_script">
<script>
  $ (function () {
    alert("Starting");
  });
</script>
</content>

local_script , , :)

, sitemesh - (, django).

+7

All Articles