I am trying to make a very simple code. I have a php value that I am trying to display in a TPL file.

PHP code:

<?php 

	include 'photochanger.tpl';

$test='my text';

?>

TPL Code:

{test}

I can tell that there is a very simple solution. Could anybody tell me what adjustments should be made so I can display the value for test on my website through my TPL file?

    I'm guessing you need to assign the variable value before you include the .tpl file, though since I don't know what that file is doing, I can't be 100&#37; sure (only about 98.5% sure).

      Ok. How do I do that though? Thanks

        This is what I have for the PHP file now.

        <?php

        $test='http://cleaverconstruction.com/images/header2.jpg';
        $gDirSmarty->assign('test', $test);
        	include 'photochanger.tpl';

        ?>

        I now get an error message:

        Fatal error: Call to a member function assign() on a non-object in /home1/cleaverc/public_html/photochanger.php on line 5

          Never mind, what I typed here originally no longer applies in view of your last reply.

            Nogdog,

            Did my second post help clarify what I am looking for? Thanks for your help.

              Max CR;10983643 wrote:

              Nogdog,

              Did my second post help clarify what I am looking for? Thanks for your help.

              Yep. Now I know it's a Smarty question, so I'll leave this to someone who actually uses/knows Smarty. (I've never felt a need to use it.)

                Ok. is there anything else i might be able to do to get this to work? It seems so simple like Im missing somehting simple

                  This isnt a smarty questino or anyhitng else either. All that you see in this page is what i am trying to do.

                  Any help please?!

                    I assumed that this line indicated a Smarty object:

                    $gDirSmarty->assign('test', $test);
                    

                    ???

                    If not, we (or at least I) need some clue as to what it is. (If it is supposed to be using Smarty, then presumably you have to instantiate that object before using it.)

                    Or if that's a red herring, then I need to know what exactly you want to do.

                      Thanks for the response. I am simply trying to create a value using php and then dispaly it in a TPL file. I got that smarty value from searching the web for a solution.

                      The TPL file states and ONLY states:

                      {test}

                      The PHP file states and ONLY states:

                      <?php

                      $test='http://cleaverconstruction.com/images/header2.jpg';
                      $monkey->assign('test', $test);
                      include 'photochanger.tpl';

                      ?>

                      I now get an error message:

                      Quote:
                      Fatal error: Call to a member function assign() on a non-object in /home1/cleaverc/public_html/photochanger.php on line 5

                      I just need my website to display "http://cleaverconstruction.com/images/header2.jpg" through the TPL file so I can move this value where i want it to be moved.

                      Thank you.

                        The quick and dirty solution:

                        <?php
                        $test = "blah blah blah";
                        $page = file_get_contents("path/to/file.tpl");
                        $page = str_replace('{test}', $test, $page);
                        echo $page;
                        ?>
                        

                          Fantastic!!! That worked perfectly!

                          For anyone else looking for help, my PHP file became:

                          <?php

                          $test='http://cleaverconstruction.com/images/header2.jpg';
                          $page = file_get_contents("photochanger.tpl"); 
                          
                          $page = str_replace('{test}', $test, $page); 
                          echo $page; 

                          ?>

                            Write a Reply...