I now also came across PHP requirement. I need some PHP to be executed before anything else. So I tried to put it into the header using the options of my topic.
Unfortunately there is no setting to put the code before
so I need to use an extern script to append the html to the PHP and then save as *.php. The PHP has to be executed so early, because only then I can modify the http headers.
So maybe this little option can be implemented.
(Of course it would be nice to be able to specify php as extension)
Overall i would be glad if we could see in the future some php integration inside bss, it would allow to do much more than only front end, but i wouldnāt expect it, but i have hopeš
Add some text before any HTML code when exporting a page (at the first character!)
Add some text after all HTML code when exporting a text
Why I need this? Because when using the file as PHP script I cannot have any output before the PHP code since this automatically changes the HTTP response. Up to now I need to use a preprocessor to update the files which is not optimal to solve such an easy problem.
Ideally allow to load the before/after code from external file at the time when exporting it. That should also be very easy to do.
It can also be used to add password protection to pages.
I really donāt see why the devs donāt allow it. They have no issues with us adding custom code inside the page HTML. Weāre simply asking for the ability to add it outside the page HTML.
I use a Python Beautiful Soup py script to do this after export (about 4 seconds) Changes the href links to .php and saves as .php. Leaves the html files alone but I have a script to delete those also after completion.
Unique code for each html page would be different, I would not use a loop or possibly use definitions to match page characteristicsā¦
import glob
import os.path
from bs4 import BeautifulSoup
# Modify main html pages and convert to php
dir_path = r"C:\MySites\mywebsite2"
for fpath in glob.glob(os.path.join(dir_path, "*.html")):
with open(fpath) as html_file:
soup = BeautifulSoup(html_file, 'html.parser')
for a in soup.findAll('a'):
a['href'] = a['href'].replace("html", "php")
print (soup.a)
new_dom_content = soup.prettify(formatter=None)
html_number = os.path.basename(fpath).rsplit('.',1)[0]
with open(html_number + '.php', 'w') as outfile:
outfile.write("<?php include('admin/runtime.php'); ?>\n")
outfile.write("ANYTHING ELSE BEFORE <!DOCTYPE html>")
outfile.write(new_dom_content)
outfile.close()
Even with the solution posted by @fotoarray it means that the publish to SFTP is redundant as the site needs to be exported for the script to run and then manually uploaded.
I know there would be issues with people trying to upload before html onto the bss server, but there could be a conditional that before will only work on publishing to SFTP.