View Full Version : loading the content of folder

10-24-2008, 11:29 PM
I was thinking, and I will try to describe it through an example because I can have a problem to express it in english.


Thanks to ajax it's possible to load external content.
I was wondering whether it is possible to do following.

1. First step.

Let say that I have a folder with some content files.
So I have a folder with content like that:


Is it possible that one html file loads automatically all files from the content folder (no matter whether there are 1 or 5 or 30)?. The general idea is, that when I click on my html file - it loads all the content files one by one, and the page will looks so:




So I don't have to modify each time my main-file when I create some content.

If this solution is possible - would it be necessary to take care, that all contentfiles are loaded into this html page?

2. Making it more complicated.

Let say, that the names of the content files are tagged (via header or filename).


As you can see,
- according 'tag1' there are 2 files with '1a', 1 file with '1b', 1 file with '1c'
- according 'tag2' there are 2 files with '2a', 2 files with '2b'
- according 'tag3' there are 3 files with '3a', 1 file with '3c'
- according 'tag4' there are 4 files with '4c'.

General idea is to use a constant formula/string for tagging (like 4letters-4letters-4letters.htm) for every content file.

I'd like to have html files capable to select which files they will load from the content folder. For example:

- mainfile1 loads content according to 'tag1' but only with the tag1a string
- mainfile2 loads content according to 'tag2' but only with the tag2a string
- mainfile3 loads content according to 'tag3' but only with the tag3a string
- but - mainfile4 loads content according to 'tag1' but only with the 'tag1b' string
...and so on

And then I can very easy distribute the content on the entire website, working only with the content files, and leaving the template.


puff... is it possible to follow javascript/ajax way?

10-25-2008, 03:35 PM
That sort of thing is generally done with server side includes and GET or POST data included with the page request. It could be done with javascript, with one exception, javascript doesn't read filenames from folders, so you would have to retrieve only known filenames (these could be of set format to allow numbers and 'tags' to be used in the filenames, but javascript will not fetch all files/filenames from a folder for processing), or use the server side to generate the listing. In any case, this is more of a project than is usually tackled in these forums. That's not to say no one will, or that someone might not have an idea where to find such code already made up. You might try Google.

10-25-2008, 05:39 PM
If you agree, I will continue my thoughts and perhaps some simple idea will come out.

Would it be simple to do if:

1. I have a folder where I put the contentfiles
2. I have one list-file where I put the names of contentfiles and include 'tags' of the main files? an example of such list woudl be:

contentfile1, mainfile1, manifile2, mainfile3
contentfile2, mainfile1, manifile2, mainfile3
contentfile#, mainfile2, manifile3, mainfile4

and then - for example:
- mainfile1 uses this list to load only these contentfiles which are tagged 'mainfile1'
- mainfile2 uses this list to load only these contentfiles which are tagged 'mainfile2'
...and so on.

and then - I still can have very simple template of my webpage.

long ago a friend wrote a script for me that loaded multiple content "onload", but each time I added something new - I had to modify the main file in 3 or 4 places (also loading order was a manual matter of regrouping), and I had to modify multiple main-files which loaded some same parts of such content.

and with such solution, I assume that:
1. I would have to add to the list-file only the names of contentfiles with tags/descriptors
2. the script would load contentfiles selected from the list according to tags declared in the main html page
3. on main html page, there would be no modifications needed, no matter how many contentfiles are loaded from external folder.