How to specify location of Unit1.html in deployment when URL <> folders?

Hi,

This is a noob question, but I have searched through the dev guide and haven't been able to figure this out. I'm probably just not searching for the right words.

TLDR: Is there some way to specify the actual location of Unit1.html/.js when it is different to the URL path?

I've written a simple one form app, played with it in the IDE and all is fine.

I'm uploaded it to our website, and can use it successfully by invoking the actual path to the project html. eg. https://code-partners.com/apps/wptest/WPTest.html

All good.

However, now I want to integrate it into the rest of our site (Wordpress), and this means the URL will not be equivalent to the folder where the static files are contained. Whereas the files are in /apps/wptest, the URL will end up being https://code-partners.com/wptest/ based on what path I make for the wordpress Page..

I've included the necessary script tags in my Page so that it loads Project1.js from the correct folder, but then in the console it throws a 404 when trying to load Unit1.html. It appears to be looking for it in the /wptest folder (what the URL suggests) rather than looking for it in the same folder as the project js.

Is there some way to tell it not to go by the URL but instead use a relative path?

Sorry, I hope that makes sense.

Cheers

Sorry, here's the error as well

Is wptest a subfolder in your project folder where unit1.html is located?
For a default new project, unit1.html for the form is in the same folder where the app start HTML file is located. And then it is loaded in a relative way, i.e. it will load the form unit1.html file as-is, i.e. without absolute path.
Other than this, the possible relative path for unit1.html is also in the project .DPR file, defined as line:
Unit1 in 'Unit1.pas' {Form1: TWebForm} {*.html};

Here you see the last part {*.html} that means the file used will be unit1.html load relatively in the same path as where other project files are (like main .html file and main project .js file)

Hi Bruno,

Sorry, I think I explained it badly. I've been thinking about it overnight and I'll try and phrase it differently.

So, the real issue is replacing Project1.html with something that is dynamically generated by another process. In my case that other process is Wordpress, but it could be another CMS or even a CRM, etc. The issue is that in this case, the URL of the "page" that calls rtl.run is not necessarily the path to the other files.

So in my case, I have page generated dynamically by wordpress. It has a URL which could vary dramatically. By default Wordpress will use something like http://example.com/?p=1234 where 1234 is the id of the page. Inside that page I load the Project js script and call rtl.run.

<script type="text/javascript" src="/apps/wptest/Project1.js"></script>

Note the changed path to Project1.js.

That works to a point, but it seems (and I need to test this more) that the generated js assumes it can use the same url to access Unit1.html, so in this example it appears it's looking for it in this location:

http://example.com/Unit1.html

whereas it is actually in the same place that I loaded the project js from (/apps/wptest/Unit1.html)

So I'm looking for a way to tell it to look for Unti1.html in http://example.com/apps/wptest/Unit1.html1 , like some sort of base url or something.

Does that make more sense? It's about the fact the URL is not necessarily related to the actual file location.

Reading the docs last night, I think I saw there is a CreateForm call that lets you specify the path. I need to play with that today and see if that let's me change anything. Any suggestions you have are very welcome.

Cheers

I've hacked around the issue, but I suspect that I'm making this harder than it should be, and I'm missing some built in attribute:

I override GetHTMLFilename in my form to prefix it with the actual path to my html file.

class function TForm1.GetHTMLFileName: string;
begin
  // Result := '/apps/wptest/' + self.UnitName + Application.GetFormExtension; // GetFormExtension is protected
  Result := '/apps/wptest/' + self.UnitName + '.html';
end;

This now successfully loads my form inside a dynamically generated wordpress page. I have some sizing issues to sort out, but it's working.

Hopefully this isn't the actual solution, but maybe it will help me explain the problem.

Cheers

Note, you can play with it here if it helps understand wptest – Code Partners

I missed this Bruno. So does this allow you to specify a path as well, so something like {apps/wptest/*.html}

1 Like

The GetHTMLFilename is a valid approach to redirect where the .HTML file is retrieved from at runtime.
What is specified in the .DPR file is for design-time purposes and sets the connection between form .PAS file and the form .HTML file. A possible path set, will not be used at runtime.

1 Like

Thanks Bruno, I'll move ahead with this approach then.

Cheers