Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Smarty for Beginners
MISCELLANEOUS

Smarty for Beginners
By: Hermawan Haryanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 156
    2003-12-28

    Table of Contents:
  • Smarty for Beginners
  • File Creation
  • The Basics
  • What about accessing a database?
  • Some fun stuff

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Smarty for Beginners - File Creation


    (Page 2 of 5 )

    Let's go back to "smartyrules" folder. In that folder, create a new PHP file with the contents of as follows:

    <?php
      # Filename: libs.inc.php

      # the exact path is defined.
      $fixpath = dirname(__FILE__);

      # changes this value according to your uploaded smarty distribution.
      # don't forget to add trailing back slash
      # change 'username' to your username on web hosting account
      define ("SMARTY_DIR", "/home/username/smarty/");

      require_once (SMARTY_DIR."Smarty.class.php");
      $smarty = new Smarty;
      $smarty->compile_dir = "$fixpath/compile";
      $smarty->template_dir = "$fixpath/html";
    ?>

    Save the file as libs.inc.php.

    Create another new PHP file, the contents as follows:

    <?php
      # filename: index.php
      require_once ("./libs.inc.php");
      $smarty->display ("index.html");
    ?>

    Save the file as index.php

    Go to "html" directory in the "smartyrules" subfolder. Create a new html file, the contents as follows:

    <html>
    <head>
    <title>My First Smarty Page</title>
    </head>
    <body>
    This is my First Smarty Page
    </body>
    </html>

    Save the file as index.html

    All set, now you can open your browser and type your address http://www.domain.com/smartyrules. You'll see your page is generated using index.html in subfolder "html" as the template. That would your first Smarty page.

    What Smarty does is compile index.html and put it in the "compile" folder then display it right away from there. You can see in the "compile" folder, there are new files, they were created by Smarty.

    More Miscellaneous Articles
    More By Hermawan Haryanto

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap