PHP Includes - being replaced with the text being included


#1

I have a site where the client is adding reviews of talks. Between each one, I want to put an include to give some navigation.
https://www.marchamsociety.org.uk/reviews.php

I have read the Include documentation but am coming unstuck probably on this caveat - “You should never put server-side code inside a content region, especially includes. Put your content regions inside the include file instead.” as I don’t really understand what it is saying.

The reviews all site in one editable region (as the client is adding new reviews to the top each month) and the <?php include 'includes/reviewnav.ssi';?> sits between each one.

When the client updates, the parser replaces the include with the text it contains, so when I update reviewnav.ssi it isn’t included.
What am I doing wrong??!! The includes outside the editable region are fine.
Thanks for any advice.
PS please excuse the archaic nature of the design of the site, it is very old and I am working on them to change it!


#2

You should never put server-side code inside a content region, especially includes. Put your content regions inside the include file instead.

That means you shouldn’t do this:

<!-- page.php - WILL NOT WORK -->
<div id="my-id" class="cms-editable">
  <?php include 'include.php'; ?>
</div>

Instead, do this:

<!-- page.php -->
<?php include 'include.php'; ?>

And then put the content region in your include file:

<!-- include.php -->
<div id="my-id" class="cms-editable">
  This is content that will be included.
</div>

#3

I think I see what you say but not sure how to implement it when I have several of the same include on the page! Will I have to put each section into a different content region with the include between each one?
What I want to do is this:

<div id="reviews" class="editable">
Review No 1
<hr>
<?php include 'includes/reviewnav.ssi';?>
Review No 2
<hr>
<?php include 'includes/reviewnav.ssi';?>
Review No 3
<hr>
<?php include 'includes/reviewnav.ssi';?>
</div>

But I think what I have to do is this

<div id="reviews1" class="editable">
Review No 1
<hr>
</div>
<?php include 'includes/reviewnav.ssi';?>
<div id="reviews2" class="editable">
Review No 2
<hr>
</div>
<?php include 'includes/reviewnav.ssi';?>
<div id="reviews3" class="editable">
Review No 3
<hr>
</div>
<?php include 'includes/reviewnav.ssi';?>

Or is there a better way of doing it?
PS thanks for the quick response - much appreciated!


#4

Just realised that I should have pasted the code differently as it took out where I had put the <div> and </div> markers. So what I sent doesn’t really make sense. In words - I have have a different div name for each review, and end the div just before the include. I have edited my previous post to show the div markers

Maybe I should rethink this!!


#5

I updated them to display correctly. In the future, you can wrap inline code with backticks and code fields with triple backticks:

This is a `<div>` in text.

```html
<div>I am a div</div>
```

#6

Correct. Splitting up the content region into multiple regions that don’t contain the PHP includes is the way to go here.


#7

Thanks for explaining - I will go off and relabel the ids and it should all work! Happy Easter!