SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am currently using something like:

    PHP Code:
    <?php

    include "template.inc";

    $to "to@domain.com";
    $from "from@domain.com";

    $t = new Template();
    $t->set_file(array(
        
    "email_user" => "email_user.ihtml",
        
    "email_admin" => "email_admin.ihtml"
        
    ));

    $t->set_var(array(
        
    "to" => "$to",
        
    "from" => "$from"
        
    ));

    $user_body $t->parse("MyOutput1","email_user");
    $admin_body $t->parse("MyOutput2","email_admin");

    echo 
    $user_body;
    echo 
    $admin_body;

    ?>
    using phplib's template class (thanks freddy!)

    anyway, i would much prefere to store these specific templates (they are are for emails and i will have quite a lot of them) in a database, i tried this, replacing email_user.ihtml with $email for example but it does not work, it apparently thinks that $email is the name of the template file as opposed to the actual text i want parsed. Any ideas?

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The set_file, set_var and set_block methods all do EXACTLY the same thing - they create an internal template variable and return a handle by which it can be referenced.

    set_file will load the information for the template variable from a specified file, while set_var will specify the template variable information in the function. As a result, if you want to store the template in a database all you need to do is retrieve it from the database and then use set_var in place of set_file to send it to the template class.

    Simply load the template from the database into a PHP variable (for example $email_user_template), then use:

    $t->set_var("email_user", $email_user_template);

    To perform the function that you previously used set_file for.

    The other (neater) way of doing it would be to extend or edit the Template class to add a new method called "set_dbtemplate" which accepts a database ID and loads the template from the database itself

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so so so so much, as well as working it out and now understand what is going on a lot better, thank you.

    I think you class idea is a good one, but i am going to complicate - i am going to try and work out how i could get an array of templates back based on an array of ids.. basically to save multiple queries. I guess doing the easy way first is an idea and then complicate it afterwards


Bookmarks

Posting Permissions

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