Generate dynamic html - html

to export some data i want to be able to generate an html output.
I have some constant content to output, like html headers and footers.
My question is how to deal with that ?
Do I have to embed some template (in a resource file) and parse it to make it dynamic ?
Do I store my static content in some constant (is there a 255 char limit?) and append them while generating the dynamic content ?
Do you have some hints, useful links, or best practices to share?
Thanks

Use the Delphi TPageProducer. It generates HTML from a 'close to HTML' template which contains special tage. You respond to these tag in an event and replace them with your own data. Works a treat.

I've created a Delphi project that handles this issue also. I wanted to create a web-platform that uses Delphi-code in the same source-files as the HTML, much like other web-scripting platforms, but still compiles a library to run. (and auto-compiles on changes)
http://xxm.sf.net/
In its basic form it compiles into library that can be run by a handler for IIS (ISAPI extension), InternetExplorer (IInternetProtocol as its own URL scheme), or a stand-alone HTTP process. (Apache module and FireFix plug-in are on the way).

Related

Global ASP function

I have an application programmed in classic asp. Now I need to create a new function that is accessible by all the files of my application, the problem is that I would have to add includes for all sites.
Does anyone know how to define this function globally without the need to add the includes?
I have already tried with global.asa but it did not work for me.
Thank you very much in advance.
a greeting
I don't believe there is a way to create an ASP function that can be called from any ASP file without including the function in the ASP page that needs to call it.
A common design pattern I use for a site (or a folder of related functionality within a site) is to create a file that contains this kind of thing -- global functions -- then include that file in every ASP file on the site/folder. One common thing this file might contain is a subroutine that emits the initial HTML before the content of the page, and another that emits everything that comes after the content. This allows me to easily give all pages a common appearance and (when combined with a common style sheet) to change that appearance without modifying each page. You can also include widely referenced functions in this file. For example, every page on my site has a login form at the top. The code to handle validating a customer's login credentials is in this global header file.

How to embed Go HTML templates into code?

I have a set of templates as files, like base.html, login.html, profile.html, header.html and so on. They are structured in folders.
It's fine to have them as separate files during development but when I deploy the app, I'd like to have them all embedded as strings or parsed and compiled templates ready to use from the code as usual.
How should I better make these templates as Go code? So that I don't have to have a templates folder in production, but everything in the single executable file?
With Go 1.16 there would be official "embed" package and the following would be possible (is possible if you read this after February 2021):
//go:embed "mytemplate.tmpl"
var myTemplate string
This code embeds mytemplate.html at compile time and it becomes available as a string (or as []byte or as a FileSystem, if you wish). No 3rd-party tools or libraries needed.
The most simple solution is to embed templates in string literal inside Go source code.
There is a tool that can help, see go-bindata.
I used go generate in some of previous projects for this type of operation, see blog post on go generate command for introduction.
As of the Go 1.16 release, there is the //go:embed comment directive.
This allows you to directly embed files in your binary.
Link for draft design of the go:embed comment directive
Link for the Github issue for go embed with some updates
In addition to go-bindata which was already mentioned, there is go-bindata-assetfs which you can use to serve static files from a webserver. It's good for Javascript, CSS, etc.

SquareSpace how to view local template?

I am currently developing a customized template of SquareSpace and I am not sure how to view the changes i have done locally? Also are there any resources out there to help me alter the templates, the documentation on the site isnt great?
Being able to develop and then display rendered squarespace (SS) templates in a local development environment (or "offline") seems to be an oft requested feature.
It's not straightforward so far as I can tell. To quote
The short answer is no. There is not currently a way to develop locally.
However, once we get site data exports working it should be a simple matter to setup a lightweight node js script to get local development running.
(source), similar answers
According to the SS docs, the templating engine is JSON Template, the styling is done by LESS and all of the data for a website is stored as JSON. The data for any page of an SS website can be viewed by appending ?format=json-pretty to the URL of the page (or &format=json-pretty if the URL already has a query string appended to it).
Here's an example of how to use the javascript version of JSON Template to render a template (view its source).
So it should be possible to set-up a local devenv. The solution would have to combine the use of the aforementioned components along with a way to combine a set of templates for any given page (e.g. combine sites.region and collections/blog.list for a blog index page). You could probably even hack together an html page along the lines of the aforementioned JSON Template example without the ability to combine templates if you just wanted to develop within a single template.

in HTML page can we use jsp code

In page.html we can use javascript code, I accept that, but can we use jsp and tld files in html files.
Please explain.
Any server-side code would need to be executed on the server, not in the browser. There's a hard separation between the server-side processing and the client-side processing. So the JSP code wouldn't be able to interact with the JavaScript code or anything like that.
In order for server-side code to be executed in an HTML file before rendering it to the browser, your server would need to be configured to process that code. It would be a matter of configuring your web server, whichever one you're using. By default I imagine it just returns .html files to the browser without any server-side processing. But you can configure your web server to treat .html files just like it would JSP files.
Keep in mind that you would need to treat those .html files like you normally would JSP files. It would have to match the same conventions for separating client-side code from server-side code.
If you configure your web server to map the text/html content type to JSP, you can.
No. JSP pages are executed on the server side and produce HTML, which is sent to the browser. JSP acts just like PHP in this regard, essentially "rendering" some HTML code and sending it off to the user. You can't embed JSP code in the HTML and send it off to the user - their browser will just do nothing with it.

HTML Include file

I have a basic web application packaged as an EAR deployed on GlassFish.
The web module has some html files.
The html files have a common footer, an html file, that I would like to extract out and make an include.
When I do, and put:
<!--#include virtual="insertthisfile.html" -->
in an html file, it does not work.
Should this work?
This is a technique called Server-Side Includes (SSI). It may not be enabled on your web host. If it is, sometimes they force a .shtml extension to be required for included files, so try renaming your file insertthisfile.shtml.
If that doesn't work, you might be able to enable SSIs in a .htaccess file (assuming your web server is Apache). You can find instructions on how to do this by googling. There's a decent set here.
If that fails, I would contact your web host and see if they have SSIs enabled.
Should this work?
Perhaps, at some special settings, with some experienced programmer, this could be useful.
In my case the include statement seems to be ignored.
I could include some text with
(embed src="include.shtml")
(/embed)
Above, I type () instead of angular brackets.
With the "embed", the setting in the header of the page does not apply to the included text; it should be repeated again, and, by default, the result is ugly.
It looks strange, as if the designers of the html did not build-in the very basic tool, the include command. For short articles, the include could save an order of magnitude in the size of files.