Skip to main content
January 17, 2017
Answered

PHP template - editable region is covering entire PHP script, not single lines

  • January 17, 2017
  • 2 replies
  • 875 views

I have created a PHP Template in Dreamweaver CS6. Inside my PHP template, I have a PHP script which consists of 60 x code lines. A single code line needs to be updated on each .php file in my website, while the other 59 x code lines will stay exactly the same on all my .php files.

In my PHP Template, I have inserted an Editable Region, while selecting the 1 x code line which I would like to make editable. However, Dreamweaver makes the entire PHP script editable; from the beginning of my script to the end of my script.

---Editable region starts here---

<?php

60 x code lines...   

?>

---Editable region ends here---

If I manually move the start/end of my editable region inside my PHP code, so that it only covers the single code line which I would like to be editable, I get a syntax error.

Is there a way for me to have only a single code line defined as an editable region, or do I need to have my entire PHP script as an editable region?

Can I perhaps use the "editable tag attribute" function to accomplish this?

Thanks in advance for your help.

This topic has been closed for replies.
Correct answer Rob Hecker2

Normally you don't use templates with PHP because a template tries to solve a problem that PHP already solves. With PHP, one usually uses include files or changes the data based on url parameters (like page.php?id=26))

But you can probably still achieve what you are trying to do by putting the 60 lines of PHP somewhere above the template and simply echo the content variable that you need to have within the template area, like this:

---Editable region starts here---

<?php

echo $your_variable;   

?>

---Editable region ends here---

2 replies

Legend
January 17, 2017

I agree with Rob - seems a sideways move using a Dreamweaver template and php combination. When I started to use php there was no reason to use a dw templates.

Rob Hecker2
Rob Hecker2Correct answer
Legend
January 17, 2017

Normally you don't use templates with PHP because a template tries to solve a problem that PHP already solves. With PHP, one usually uses include files or changes the data based on url parameters (like page.php?id=26))

But you can probably still achieve what you are trying to do by putting the 60 lines of PHP somewhere above the template and simply echo the content variable that you need to have within the template area, like this:

---Editable region starts here---

<?php

echo $your_variable;   

?>

---Editable region ends here---

January 17, 2017

Thank you very much for the information. I should probably read up on PHP usage in website design.

Just to illustrate what I'm trying to do: My website will contain approx 250 .php pages. Each page will read from a large database, and output a series of text based on an <IF> statement. It is this <IF> statement which is unique to each .php page:

<?php

     --code which reads from database--

if ($entries_country=='Denmark' && $entries_city=='Copenhagen'){

     --code which outputs a series of text based on the above <IF> statement

?>

As a comment to what you are both saying, why would I not use a template to control the other parts of my PHP code?

I have a feeling I'm using PHP in my website design the wrong way?

Legend
January 17, 2017

uiofuf98ewufew wrote:

As a comment to what you are both saying, why would I not use a template to control the other parts of my PHP code?

I have a feeling I'm using PHP in my website design the wrong way?

Because php 'includes' are a much better way of building templates:

<?php include('includes/navigation.php'); ?>

<?php include('includes/sidebar.php'); ?>

<?php include('includes/footer.php'); ?>

When you use a .dwt template you need to upload ALL of the pages to your sever which use that template everytime you make a change to your template file...................long winded and boring.

As an example IF you use a .dwt template for the navigation and change the naviagtion you will have to upload 250 pages to your server. If you use a php include file for your navigation all you do is change that and upload just the 1 file NOT 250 files.