You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Speelmon, Lance Day" <la...@indiana.edu> on 2009/07/29 22:35:22 UTC
when does currentNode get initialized in an esp?
As a Sling newbie, could someone help me understand when currentNode gets initialized in an esp file? The following script shows that currentNode is undefined in the $(document).ready context, but is defined later(?) within the <h1> tags. Thanks, L
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="/notifications/js/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
alert(typeof currentNode);
// var props = currentNode.getProperties();
// alert(typeof props);
// $.each(props, function(i, item){
// $("#console").append(i + ": " + item + "<br/>");
// });
});
</script>
<body>
<h1><%= currentNode.path %></h1>
</body>
</html>
Lance Speelmon
Scholarly Technologist
Re: when does currentNode get initialized in an esp?
Posted by "Speelmon, Lance Day" <la...@indiana.edu>.
That is a great help! Thanks, L
Lance Speelmon
Scholarly Technologist
On Jul 30, 2009, at 7:03 AM, Vidar Ramdal wrote:
>> Speelmon, Lance Day wrote:
>>>
>>> As a Sling newbie, could someone help me understand when
>>> currentNode gets
>>> initialized in an esp file? The following script shows that
>>> currentNode is
>>> undefined in the $(document).ready context, but is defined later
>>> (?) within
>>> the <h1> tags. Thanks, L
>
> 2009/7/29 Branden Visser <br...@uwindsor.ca>:
>> 'currentNode' is only accessible through server-side JavaScript.
>>
>> Your first access of currentNode is client-side, and therefore is
>> undefined.
>
> As Branden says, currentNode is a server-side variable, but it's
> sometimes handy to have the full object available client side. To do
> so, you can include currentNode's JSON rendering:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> [...]
> <script type="text/javascript" charset="utf-8">
> // Client-side javascript
> var currentNode = <% // Server-side javascript:
> sling.include(currentNode.path + ".json");
> %>;
> // Client-side javascript
> alert("currentNode: " + currentNode.path);
>
> </script>
> [...]
>
> --
> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> Akersgata 16, N-0158 Oslo, Norway
> +47 21 531941, ext 2070
Re: when does currentNode get initialized in an esp?
Posted by Vidar Ramdal <vi...@idium.no>.
> Speelmon, Lance Day wrote:
>>
>> As a Sling newbie, could someone help me understand when currentNode gets
>> initialized in an esp file? The following script shows that currentNode is
>> undefined in the $(document).ready context, but is defined later(?) within
>> the <h1> tags. Thanks, L
2009/7/29 Branden Visser <br...@uwindsor.ca>:
> 'currentNode' is only accessible through server-side JavaScript.
>
> Your first access of currentNode is client-side, and therefore is undefined.
As Branden says, currentNode is a server-side variable, but it's
sometimes handy to have the full object available client side. To do
so, you can include currentNode's JSON rendering:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
[...]
<script type="text/javascript" charset="utf-8">
// Client-side javascript
var currentNode = <% // Server-side javascript:
sling.include(currentNode.path + ".json");
%>;
// Client-side javascript
alert("currentNode: " + currentNode.path);
</script>
[...]
--
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Akersgata 16, N-0158 Oslo, Norway
+47 21 531941, ext 2070
Re: when does currentNode get initialized in an esp?
Posted by Branden Visser <br...@uwindsor.ca>.
Hi Lance,
'currentNode' is only accessible through server-side JavaScript.
Your first access of currentNode is client-side, and therefore is undefined.
Best,
Branden
Speelmon, Lance Day wrote:
> As a Sling newbie, could someone help me understand when currentNode gets initialized in an esp file? The following script shows that currentNode is undefined in the $(document).ready context, but is defined later(?) within the <h1> tags. Thanks, L
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
> <html>
> <head>
> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
> <script type="text/javascript" src="/notifications/js/jquery/jquery-1.3.2.js"></script>
> <script type="text/javascript" charset="utf-8">
> $(document).ready(function(){
> alert(typeof currentNode);
> // var props = currentNode.getProperties();
> // alert(typeof props);
> // $.each(props, function(i, item){
> // $("#console").append(i + ": " + item + "<br/>");
> // });
> });
> </script>
> <body>
> <h1><%= currentNode.path %></h1>
> </body>
> </html>
>
>
>
> Lance Speelmon
> Scholarly Technologist
>
>