Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    137
    Thanks
    1
    Thanked 0 Times in 0 Posts

    question about smarty templates

    i have 3 template folders called template1 template2 and template3

    in the index.php file when i use the following and access
    http://localhost everything works fine and i am able to display the value of variables defined in index.php

    $smarty->template_dir = 'c:/wamp/www/smarty/templates';


    however when i change to
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/template1';
    or
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/template2';
    or
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/template3';

    and when i access http://localhost i am getting the output of
    $smarty->template_dir = 'c:/wamp/www/smarty/templates'; where as i have made a small chane in the index.tpl for template1,2and 3 a simple line = template 1 and then followed by displaying the value of variables


    why am i getting the output of
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/templates';

    when i am changing the $smarty to
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/template1';

    i have cleared the cache and also tried
    http://localhost?clearcache=1 and
    http://localhost?clearall=1

    however i still see the output of
    $smarty->template_dir = 'c:/wamp/www/smarty/templates/templates';

    please advice.

    thanks.

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    $template_dir

    This is the name of the default template directory. If you do not supply a resource type when including files, they will be found here. By default this is ./templates, meaning that Smarty will look for the templates/ directory in the same directory as the executing php script.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    137
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for replying

    i did not quite get what you are saying can you explain what i am supposed to do and which code should i change from the below code i have presently

    require('c:/smarty/libs/Smarty.class.php');

    $smarty = new Smarty;

    $smarty->template_dir = 'c:/wamp/www/smarty/templates/template1/';
    $smarty->config_dir = 'c:/wamp/www/smarty/configs';
    $smarty->cache_dir = 'c:/smarty/cache';
    $smarty->compile_dir = 'c:/smarty/templates_c';

    $smarty->assign('var1','Smarty Template Variable 1 template3');
    $smarty->assign('var2','Smarty Template Variable 2 template3');

    $smarty->display('index.tpl');

    thanks.

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    It doesn't seem like there's much wrong with what you have above. This is what I typically do:

    PHP Code:
    include_once 'Smarty.class.php';
    include_once 
    'Smarty_Compiler.class.php';

    // make sure it worked okay
    if ( !class_exists('Smarty') )
    {
        print 
    "Whoops, no Smarty!";
        exit;
    }

    // initialize smarty
    $smarty = new Smarty();

    $smarty->template_dir "$templatedir";
    $smarty->compile_dir SMARTY_DIR "templates_c";
    $smarty->config_dir SMARTY_DIR "configs";
    $smarty->cache_dir SMARTY_DIR "cache";

    $smarty->assign"var""value!" );
    $smarty->display"main.tpl" ); 
    Which is pretty much the exact same thing you do. So my first guess would just be that you have a bug in your code somewhere - do you happen to have a line that says:

    '$smarty->template_dir = 'c:/wamp/www/smarty/templates';'

    somewhere outside of your php tags? I really can't think of any other reason why it would output exactly that statement, other than having a mis-placed line of code outside of php tags, and therefore interpreted as plain text.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •