9 Replies Latest reply: Feb 12, 2011 2:33 PM by thersher RSS

    Templates and PHP

    thersher Community Member

      I'm learning PHP and MySQL, and I see I have an option to create a PHP template (using CS4), instead of a regular HTML template. When I do this however, it originally creates a .php file and saves it in the Templates folder. Then, when I makes changes and save, it will save another copy and give it a dwt.php extension. Should I just use a normal HTML template, then save as a .php file instead of .html for my pages? Or should I use the php template, but save it with a .dwt extension instead of the default .php and then build my pages off that?

      Seriously confused, so thank you for any help!

        • 1. Re: Templates and PHP
          Nancy O. CommunityMVP

          DWT = Dreamweaver Template.

           

          Part I

          Build your page with all the elements you intend to use in the site.  Preview and test in all browsers.  When you're totally satisfied with the way the page looks and performs, then Save As .dwt file.  Add editable regions for things that will change from page to page.  Save again.  Close template.

           

          Part II

          File > New page from Template.  Save As index.php.

          Repeat for other site pages.

           

           

          Nancy O.
          Alt-Web Design & Publishing
          Web | Graphics | Print | Media  Specialists 
          http://alt-web.com/
          http://twitter.com/altweb

          • 2. Re: Templates and PHP
            MurraySummers CommunityMVP

            To expand a little on Nancy's reply, you do NOT create a template.  Then add content to the template and save that template file with an *.php or *.html extension.  That will not work.  To create (or spawn) a child page based on your template, you have to use the menu option FILE > New... > Page from Template.  That will work!

            • 3. Re: Templates and PHP
              thersher Community Member

              Yes, I know that, thank you, learned that the hard way years ago!

              I'm curious as to why then, that the option of creating a template with all those file extensions is even there, if the only way to use a template properly is with the dwt extension?

              • 4. Re: Templates and PHP
                MurraySummers CommunityMVP

                if the only way to use a template properly is with the dwt extension?

                 

                That's not the case, and it was not asserted to be by either of our replies.  When you create a PHP template, the filename will be *.dwt.php, and that's how it should be.  When you create a CF template, the filename would be *.dwt.cfm, again as it should be.

                 

                It's this way so that any server scripting that might be present in your template file would NOT be visible to someone who might try to browse to it on the server (assuming you had uploaded the template file in the first place - something that is only necessary if you wanted to share the file with a colleaguesince DW templates have no function on the server, nor have they ever had).

                • 5. Re: Templates and PHP
                  thersher Community Member

                  Okay, but since I want to create PHP files, don't I want to use a PHP template then? Nancy's answer was to create a regular DWT template, then save as a PHP file. Will both ways work properly?

                  • 6. Re: Templates and PHP
                    MurraySummers CommunityMVP

                    Will both ways work properly?

                     

                    There is no 'both ways.'  Nancy's answer is correct - create a PHP file, build it, then use FILE | Save as Template.  It will work.

                    • 7. Re: Templates and PHP
                      thersher Community Member

                      Oh boy, I'm really confused now. Sorry for sounding so ignorant (this is my first time at PHP), but when I normally build a site, the first thing I do is select File > New > Blank Template. Up until now I always select HTML template, and then select the layout I want for the accompanying CSS and save as a template (.dwt) file. Then when I'm creating the actual pages I select File > New > Page from template, select the template I just built, blah, blah, blah.

                       

                      So, since my end game is to have a PHP file instead of an HTML file, do I select File > New > Blank Template > PHP Template (instead of HTML)? I've tried this and it wants to save the file with the .dwt.php extension. Is that what I should be doing?

                       

                      Nancy's answer led me to believe that I simply create a normal HTML file, with the appropriate PHP code in it of course, save as a template (.dwt) and then create my page from that template and save as a .php file.

                      • 8. Re: Templates and PHP
                        MurraySummers CommunityMVP

                        FILE | New > Blank Template > PHP template - this will work

                         

                        FILE | New > Blank Page > PHP > build, build, build then FILE | Save As Template - this will work

                         

                        Go for it!

                         

                        Either of those methods will create *.dwt.php templates.  DW assumes that when you spawn a child from such a template, it is to be a PHP page.

                         

                        Message was edited by: Murray *ACP*

                        • 9. Re: Templates and PHP
                          thersher Community Member

                          Awesome, that's much more clear, thank you so much!!