Announcement

Collapse
No announcement yet.

templates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • templates

    ok, lets say i was to attempt to make my own script, how exactly would i do it template-based. such as i can either get them from a database or .html files within /templates.

    thanks

  • #2
    Originally posted by Game Wizards
    ok, lets say i was to attempt to make my own script, how exactly would i do it template-based. such as i can either get them from a database or .html files within /templates.

    thanks
    I've also been wondering, I'd like to make something similar to vBulletin's template system where I can use doouput functions or something and be able to use variables in the template .

    Comment


    • #3
      from looking in the vbulletin code i can't actually work out how everything works exactly, but i get the BASIC and i mean really basic idea.

      Comment


      • #4
        I think, ( I think )

        They create the Specific Code needed to create the variable eg User Info - Username. So they would query the user table and set it as a variable? Then when in AdminCp - Templates you will able to type that variable in , eg $bbuserinfo[username] and it would execute that Query from the user table. Just my 0.02$.

        Comment


        • #5
          Originally posted by wslxveg
          I think, ( I think )

          They create the Specific Code needed to create the variable eg User Info - Username. So they would query the user table and set it as a variable? Then when in AdminCp - Templates you will able to type that variable in , eg $bbuserinfo[username] and it would execute that Query from the user table. Just my 0.02$.
          Make a template function. Pass to it as a paramater an assotiative array of values you want to replace (IE $tempvar = array('name_in_template' => 'value to replace') ). Then get the entire template string from file/db whatever and just do this to it....


          PHP Code:
          $string preg_replace("/\{(\w+)\}/e""\$tempvar[\\2]"$string); 
          Assuming that { and } is around template "variables" that is. That will replace values in the template. Then you can improve on this on your own, like caching the template strings and whatnot.

          PPL may say this is slow, but its not that slow really if you cache stuff and stuff, and unless you need like a uber-fast script, this way is fine.

          Comment


          • #6
            Thanks i am coo man .. i'll have a mess around with it.

            Comment


            • #7
              I think vB just stores templates with php variables ($vboptions['description'], for example is the meta description) then they eval it.

              Comment


              • #8
                well i know to call templates you can always do this

                PHP Code:
                <?php
                chdir
                ("/fullpathtoforums/");
                require_once(
                "./global.php");
                eval(
                'print_output("' fetch_template('templatename') . '");');
                ?>
                and simply that will call the template out of the database granted it in that style

                Comment


                • #9
                  Originally posted by Faranth
                  well i know to call templates you can always do this

                  PHP Code:
                  <?php
                  chdir
                  ("/fullpathtoforums/");
                  require_once(
                  "./global.php");
                  eval(
                  'print_output("' fetch_template('templatename') . '");');
                  ?>
                  and simply that will call the template out of the database granted it in that style
                  I believe he said he wanna make his own template system

                  Comment


                  • #10
                    thats quite abit of work, esp to make a good one

                    Comment


                    • #11
                      a really simple method is as follows:
                      PHP Code:
                      function get_template($name)
                      {
                         
                      $template file_get_contents('./templates/' $name '.tpl');
                         
                      $template str_replace('"''\\"'$template);
                         
                      $template str_replace('\\''\\\\'$template);
                         return 
                      $template;
                      }
                      $title 'Main Page';
                      $var2 'index.php';
                      eval(
                      '$output = "' get_template('index') . '";'); 
                      and the template:
                      Code:
                      <a href="$var2">$title</a>
                      and the output:
                      Code:
                      <a href="index.php">Main Page</a>
                      Not sure if you can get any info out of that, but that's essentially how the vb2.x template engine works. (Only it gets it's templates from the database).

                      I've written a lot more complex one than that, but I'm not at liberty to give out the code for it.

                      vB3's works on the same principal as the one I just posted, only they change <if> tags into ternary statements, and eval() that.

                      Comment


                      • #12
                        ok thanks again everyone, i'll let you knowhow it goes when i've had a mess around

                        Comment

                        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                        Working...
                        X