Adding Dynamic Content to a Webpage

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Adding Dynamic Content to a Webpage

Postby chriswadams » 19. October 2020 15:41

Hello All:

I'm trying to create a small (but hopefully, growing) website, and I want to include a sidebar that will lead to different sections of the site. It seems like the easiest way to do this, and keep the site manageable as it grows, is to maintain a separate file for the sidebar, and include it on each page with a scripting language like PHP or Javascript. That way, as the site grows, and new sections are added, I will only have to change a single file to update the sidebar on all pages at the same time.

However, Altrea wrote in a pinned thread:

You are trying to use php code in html files.

This will not work because by configuration Apache will not send html files through the php interpreter.


I note that the same rule applies to Javascript. Now, I understand the reasoning behind this decision, but it seems that without the use of a scripting language, it would be nearly impossible to create a dynamic web page, unless I'm missing something. Is there a better tool for creating dynamic content? If so, could someone please give me a pointer in the right direction? And if not, how do other sites include dynamic content? Any help would be appreciated.

-Chris Adams
chriswadams
 
Posts: 1
Joined: 29. September 2020 09:11
XAMPP version: 7.4.9
Operating System: Windows 10

Re: Adding Dynamic Content to a Webpage

Postby Altrea » 19. October 2020 18:21

Hi Chris Adams,

chriswadams wrote:It seems like the easiest way to do this [...] is to maintain a separate file for the sidebar, and include it on each page with a scripting language like PHP [...]

However, Altrea wrote in a pinned thread:

You are trying to use php code in html files.

This will not work because by configuration Apache will not send html files through the php interpreter.

This is no contradiction. You can of course include a html file into a php script. The included file will get loaded and included by the php interpreter because the initial script which is requested is a php file and will get interpreted by an php interpreter.

But it cannot work the other way round. So you cannot request a .html script nd use php code in it.

Including a sidebar into each side is one possible solution. The other easy solution would be a main template file (header, sidebar, etc) which includes the body content based on the url parameters.
key word for this is "front controller". Each request is routed through a central index.php file.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11952
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 141 guests