Results 1 to 10 of 10

Thread: Trying to find a good tutorial - inserting {tags}

  1. #1
    Join Date
    May 2011
    Location
    Washington, USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trying to find a good tutorial - inserting {tags}

    Hi, Ive been doing google searches for this for hours but no luck. Was wanting to learn how to insert into templates information by using the tags such as {header}, {sidebar}, stuff like that where {sidebar} would bring up some info from a php page. Not sure what this process is even called for me to corectly search for it. Any help would be appreciated.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What kind of system are you using? As far as I know, there isn't any standard name for that, and it's not actually part of PHP. You can use it in PHP, but it's not a default. You'll need to use str_replace() or regular expressions to find and fix the content.

    You could get some insight looking at a bbcode tutorial for PHP-- replacing user-input with real code.

    You might find some more specific things for "inserting variables into templates" or replacing 'variables' with 'constants'.



    While writing this, I wanted to check that constants don't work in {} within double quoted strings. Some things, like variables, will be output within {} inside strings defined in double quotes like ".

    But this code shows that constants don't work like that:
    PHP Code:
    <?php
    define
    ('test','value');
    echo 
    test;
    //result 'value'
    echo "{test}";
    //result '{test}'
    ?>
    So you will need to use some sort of replacement function.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What kind of system are you using? As far as I know, there isn't any standard name for that, and it's not actually part of PHP. You can use it in PHP, but it's not a default. You'll need to use str_replace() or regular expressions to find and fix the content.

    You could get some insight looking at a bbcode tutorial for PHP-- replacing user-input with real code.

    You might find some more specific things for "inserting variables into templates" or replacing 'variables' with 'constants'.



    While writing this, I wanted to check that constants don't work in {} within double quoted strings. Some things, like variables, will be output within {} inside strings defined in double quotes like ".

    But this code shows that constants don't work like that:
    PHP Code:
    <?php
    define
    ('test','value');
    echo 
    test;
    //result 'value'
    echo "{test}";
    //result '{test}'
    ?>
    So you will need to use some sort of replacement function.




    By the way, any good (detailed) tutorials about PHP templating should have information about this sort of thing eventually. You can also use other methods instead if you prefer.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I've seen some CMSs that use this type of markup, though I can't recall where. It was some time ago; most are moving away from the concept.

    What's going on is:

    1) the CMS (using PHP) parses the entire document, looking for these "tags."
    2) if it finds one, it runs the associated function and replaces the tag with the function return value.

    This makes for a long, inefficient process. newer CMSs store the information about "what should be inserted where" in the database, and insert it directly in the first place. Alternatively (in many cases - not all), you could simply break into PHP and call the function directly:
    PHP Code:
    <?php print some_function(); ?>
    Are you building something new, or trying to modify an existing system?

    Edit:

    posted at same time as Djr.

    BTW Daniel:

    PHP Code:
    $S 'strval';
    define('test','this is a test');

    echo 
    "{$S(test)}"
    Last edited by traq; 06-07-2011 at 08:09 PM.

  5. The Following User Says Thank You to traq For This Useful Post:

    djr33 (06-07-2011)

  6. #5
    Join Date
    May 2011
    Location
    Washington, USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the responses. I think I might have worded it wrong. What I am trying to do is to alter an exsisting script. It is a real basic php login script with admin features.

    What I would like to do is to create a template like I have seen on a couple of different sites that have an .tpl extension for the page. The page is made up with html mark up with div, loops, tables, and such. Inside the tables are just links to information such as {body}, {memb_info}, {sidebar}, stuff like that.

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Without knowing more specific information about this particular script, we can't help. As we've explained, it is some sort of search and replace operation, so that probably is how the existing script works.

    Do you have a link to the script? Maybe you could ask the creators.

    I've never heard of the .tpl extension. It might be a format created (actually, it's probably just text, like in a .txt) specifically for this templating project.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    May 2011
    Location
    Washington, USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    The script I am using is
    http://evolt.org/PHP-Login-System-wi...ts_per_page=50

    One of the places I have seen this in use is on the ventrino traffic exchange script. It has to be one of the most efficient ways of making a template and calling up funtions that I have seen. By doing it the way they did it made it so simple to edit just about any part of the script from the admin section without haveing to ftp into the site and overwrite, or upload files. Site is here - http://www.ventrino.com/

    Attached is the .tpl file from the ventrino script that I would like to learn how to make. I put it in a zip file since the upload doesn't support .tpl extensions.

  9. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    ... does the evolt script use this templating system? (it doesn't look like it.)

    the " .tpl " file you attached is just a plain text file (i.e., typically having a .txt extension) that was named with a different extension. It has absolutely no PHP code in it. It would work as I described above: php parses the file, looking for "keywords" (e.g., {JavaScript} ), and then inserts new content in their place, depending on what the keyword is.

    Other than that, this process has nothing to do with PHP: it could be done just the same in most server-side languages, but it is not a "standard" feature of any of them. You would need to write the processing logic yourself.

    integrating it with your scripts from evolt would be even more complex, since they weren't designed with anything like this in mind. I would recommend breaking into php at the appropriate points on your page and simply using the include() function.

  10. #9
    Join Date
    May 2011
    Location
    Washington, USA
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks so much for answering my questions. I did find what I was looking for and your right, it doesn't have anything to do with php. It is called Smarty and is a template enging for php language. I'm sure you have probably heard about it. If not here is a link to what I am talking about. http://www.smarty.net/about_smarty

    For now though I think I will stick with php and using the include() function like you sugested. I will study Smarty and maybe use it later. I would appreciate an unbiased view of using the smarty template system though if you know about it.

  11. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    like I said, any parsing-based system is going to be less efficient than organizing things to be done the way you want in the first place. Instead of using keywords, this approach might be better:
    PHP Code:
    $HEADER func_builds_header();
    $MENU func_builds_menu();
    $ETC and_so_forth();

    $template '
    <!doctype html>
    <html>
    <head><meta charset="utf-8"><title>Page template</title></head>
    <body>
    <div id="header">'
    $HEADER .'</div>
    <div id="formatting_wrapper">
       <div id="menu">'
    $MENU .'</div>
       <div id="etc">'
    $ETC .'</div>
    </div>
    </body>
    '
    ;

    print 
    $template
    you could also simply include() the template file after all your content has been generated.

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
  •