Joshcamas
Joshcamas

Reputation: 31

how to input a chunk of html with php

I am currently working on a website that uses a login system I made. I have a div that holds a bar that goes on the top of the website. This bar is supposed to change depending if you're a guest, logged in, or a admin. (Therefor there are three separate divs - guestmode, membermode and adminmode)

I have tried to make php print the html when wanted, and it worked. The only problem is that it's messy and not at all easy to edit.

Is it possible for php to print html without using 'echo' or 'print', but copying from another file? Basically I want to copy normal html syntaxed-code from a file somewhere and turn it into something that php can print, then of course print it.

Is there something out there that can do that?

Thanks in advance!

Upvotes: 0

Views: 295

Answers (2)

fiction
fiction

Reputation: 586

Its seems like you need a templates.

See mustache (examples and docs - https://github.com/bobthecow/mustache.php)

Upvotes: 1

Ted Phillips
Ted Phillips

Reputation: 171

For PHP, use something like:

echo file_get_contents('path/to/my_html_snippet.my_ext'); // echo instantly
$stored = file_get_contents('path/to/my_html_snippet.my_ext'); // or save it for later in a string

Create a file at path/to/my_html_snippet.my_ext that contains the HTML you want to print.

Upvotes: 2

Related Questions