Nes

 view release on metacpan or  search on metacpan

share/examples/nesblog/en/items/Tutorial.nhtml  view on Meta::CPAN

<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<ul>
    <li><a href="#name">NAME</a></li>
    <li><a href="#install_nes">Install Nes</a></li>
    <li><a href="#create_work_space_for_tutorial">Create Work Space for Tutorial</a></li>
    <li><a href="#create_first_nes_template">Create first Nes Template</a></li>
    <li><a href="#includes_and_object">Includes and Object</a></li>

    <li><a href="#nes_environment_variables">Nes Environment Variables</a></li>
    <li><a href="#conditional_replacement">Conditional Replacement</a></li>
    <li><a href="#data_tables">Data Tables</a></li>
    <li><a href="#plugins">Plugins</a></li>
    <li><a href="#forms">Forms</a></li>
    <li><a href="#see_also">SEE ALSO</a></li>
</ul>
<p>
<br>
</p>
<hr name="index" />
</div>
<!-- INDEX END -->
<br><h3><a name="name">NAME</a></h3>
<p>Nes::Tutorial - Step by Step Nes Tutorial.</p>
<p>
</p>
<hr />
<br><h3><a name="install_nes">Install Nes</a></h3>
<p>See: <a href="./?item=Installation">Installation</a></p>
<hr />
<br><h3><a name="create_work_space_for_tutorial">Create Work Space for Tutorial</a></h3>
<p>We assume you already have installed and enabled Nes for cgi-bin.</p>
<p>According to its distribution its web root directory could be in 
/var/www/html, /var/www/htdocs, etc.</p>
<p>For this tutorial we will assume that your web root directory is
/var/www, change it throughout the tutorial if needed.</p>
<p>Create a working directory on your web root directory with the 
name nes_tutorial</p>
<pre id="comment">
    mkdir /var/www/nes_tutorial</pre>
<p>The next step is to set this directory to make it possible executing 
Nes templates, is done with the shell command:</p>
<pre id="comment">
    set_nes_site</pre>
<p>Configured:</p>
<pre id="comment">
    set_nes_site --dir_cfg=/var/www/nes_tutorial</pre>
<p>With this we have created a file .htaccess with the configuration
because Nes templates can execute in this directory.</p>
<p>The .nes.cfg file serve to configure Nes and also for your own
Perl script or application. There is a value that needs to be changed,
otherwise Nes release a warning:</p>
<pre id="comment">
    private_key</pre>
<p>It is a password used to encrypt data such as cookies, so it is very 
important to give a value to private_key.</p>
<p>Create a file in /var/www/nes_tutorial with the name .nes.cfg, with the
following content.</p>
<p>/var/www/nes_tutorial/.nes.cfg:</p>
<pre id="comment">
    private_key      = ChangeIt
    nes_tutorial_var = test variable</pre>
<p>Change 'changeit' with the password you want. And with this 
nes_tutorial is ready to work.</p>
<p>
</p>

<hr />
<br><h3><a name="create_first_nes_template">Create first Nes Template</a></h3>
<p>Nes templates have the extension .nhtml, any file with this extension, 
in nes_tutorial directory, will be treated as a Nes template.</p>
<p>Create a file named 'nes_01.nhtml' in 'nes_tutorial' with following 
contents:</p>
<pre id="comment">
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Nes Tutorial&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;b&gt;Hello Nes Tutorial&lt;/b&gt;
      &lt;/body&gt;
    &lt;/html&gt;</pre>

<p>To show it works:</p>
<pre id="comment">
    <a href="http://localhost/nes_tutorial/nes_01.nhtml">http://yousite/nes_tutorial/nes_01.nhtml</a></pre>
<p>* Change 'yousite' with your domain or 'localhost'</p>
<p>'nes_01.nhtml' has no special feature, is only HTML. To include dynamic
content, must tell Nes to run a script for this template.</p>
<p>We therefore need a Perl script. Creates a file named 'script_02.pl' 
in 'nes_tutorial' with the following contents:</p>
<pre id="comment">
    #!/usr/bin/perl

    use Nes;
    my $nes = Nes::Singleton-&gt;new();

    $nes-&gt;out();

    1;</pre>
<p>It is very important that Nes scripts returns 1, or displays an error. 
Another feature is that you do not need permission of execution to run
the script, unless you want run the script and not the template.</p>
<p>Now we tell the template that our script is 'script_02.pl' with
the Tag '&#123;: NES 1.0 ( 'script_02.pl' ) :&#125;'</p>

<p>Therefore we create a new template with the name 'nes_02.nhtml' and
the following contents:</p>
<pre id="comment">
    &#123;: NES 1.0 ( 'script_02.pl' ) :&#125;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Nes Tutorial&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;b&gt;Hello Nes Tutorial&lt;/b&gt;
      &lt;/body&gt;
    &lt;/html&gt;</pre>
<p>When we do:</p>
<pre id="comment">
    <a href="http://localhost/nes_tutorial/nes_02.nhtml">http://yousite/nes_tutorial/nes_02.nhtml</a></pre>



( run in 0.699 second using v1.01-cache-2.11-cpan-39bf76dae61 )