Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
External JS and CSS Files
#11
Hi, Alexandre

I'm afraid I'm confused, so I have separated only on Html first.
A. I have tested as you suggested. For reference path within the html file, I came to the following conclusion.
1. Notice "../wwwroot" in front of your existing path --> Work fine
2. Notice "../" in front of your existing path --> Work fine
3. Notice existing path directly such "assets/myjs/myjs.min.js" --> Work fine ( Please consider in this case whether this is actually correct or not. But I tested it and it works fine. )

---------------------------------------------------------

B. And for use ContentFiles.Add [I use to css reference] or PageContext.AddBodyScriptFile. [I use to js reference] within an IWForm.
I found that only these 2 cases work well.
Such :
1. ContentFiles.Add('/assets/vendor/bootstrap/css/bootstrap.min.css');
2. ContentFiles.Add('assets/vendor/bootstrap/css/bootstrap.min.css');
Note : I have attached a sample project filewith this together and wriote comment in case it works and does not work in "frm01" unit

Please consider if it is correct or not? or
How should it be?

-------------------------------------
------------------------------------
Note :
Considering the common point of both cases A and B, what works well in both cases is that direct path references (sucah : "assets/vendor/bootstrap/css/bootstrap.min.cs") are unobtrusive and seem to fit perfectly.
Is it correct?
------------------------------------

Thank you


Attached Files
.zip   TestProject-2.zip (Size: 904.42 KB / Downloads: 1)
Reply
#12
In case A:

1) It works fine because IW is designed to handle this case.

2) It works fine eventually. In your case it works. In other cases it may not work, so don't use it

3) assets/myjs/myjs.min.js is also another case that it may or may not work fine. It really depends on the folder structure. I'd not use it either

In case B:

1 and 2) When you add files to ContentFiles list, they are pre-processed before rendering. The URL base is added to the file path, if they are relative paths, based on their type (i.e. extension). CSS files will definitely receive the URL base. So they work the same because IW is designed to handle these cases as well.

So, in short:

If you are using relative URL addresses in your template files, use case (A-1)

If you are adding files to the ContentFiles list of your IWForm, use either B-1 or B-2, they should both work.

Another case not covered here is, for instance, image files. If you are using IWImageFile (or any other control that has an image file reference property) use '\the-wwwroot-subfolder\the-image-filename.png'. It will always work regardless of the project type.

Hope it clears your doubts
Reply
#13
Hi, Alexandre

Thank you very much for your detailed explanation.

But there is one thing that I still have doubts about specifying the path of the tag that is displayed about the image. Let me give you two examples:


1. img tag :

Code:
<img src="../images/img1.png" />




2. image in css style tag

Code:
<style>
  .myBg {
      background: url(../images/background/bg1.jpg) no-repeat center;
  }
</style>


Both of these may be declared within html or css or js files.
for the right way and coverage in all cases
How should I specify these paths?



Thank you
Reply
#14
These cases should work using the root relative path, starting with the slash, so it would be:

<img src="/images/img1.png" />

That's what IW itself renders for when rendering an IMG tag
Reply
#15
Thank you Alexandre,

For my case if I use img tag on the html file. There are only 2 cases in which it can display images correctly.

<img src="images/img1.png" />

<img src="../images/img1.png" />
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)