Gossamer Forum
Home : Products : Gossamer Links : Discussions :

[Suggestion] Template path change for file includes

Quote Reply
[Suggestion] Template path change for file includes
Alex & GT staff,

Currently Template path used in GT::Template to include a file, is relative to the template dir:
Quote:
must be in the template's root directory which is defined using $obj->root, or '.' by default.
I suggest you to make possible to use both absolute & relative paths in file includes.

1) Relative path to template directory (currently used)
__a) The relative include tag looks like following: <%include test.html%>
__b) The file is loaded from path relative to the template directory:
/cgi-bin/gforum/admin/templates/


2) Absolute path relative to the website root (my suggestion)
__a) Include tag using Absolute path should look like following:
_____1st example: <%include /cgi-bin/lsql/admin/test.html%>
(So if we use this tag in E.g: Gforum, it would be possible to use the same template even in Links SQL...)
_____2nd example: <%include /mytemplates/test.html%>
(this solution could make possible for us to use a central template repository for the whole site)
__b) So the file is loaded from path absolute from to the website root:
In 1st example the the file is included from path: /cgi-bin/gforum/admin/templates/
In 2nd example the the file is included from path: /mytemplates/

The logic to distinguish relative and absolute paths:
- if our file name starts with / sign, then we use absolute path to load the file
- else our file name is not starting with / sign, so we use relative path to template root to load the file

There are many advantages of this solution, we could even create sitewide template solutions. I think it would be a very easy & quick modification, so does not need too much work.
I'm very exited, when will this feature implemented.

Alex, I already used this kind of solution successfully, altough not in LSQL, yet.
I think, I could do the change, but I don't want to do any changes in main LSQL module codes, to maintain my LSQL compatibility.
Let me know, what do you think about suggestion, and if you want to implement it or not.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] [Suggestion] Template path change for file includes In reply to
Alex, did you see this suggestion? Opinion?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] [Suggestion] Template path change for file includes In reply to
hello

I use an extra include set outside the template sets because I use lot of includes (header, footer, navig etc)

I include this like:

<%include ../includes/header.txt%>

in my templates and it works properly, so I don't see any problems about this.
Quote Reply
Re: [ridesworld] [Suggestion] Template path change for file includes In reply to
Thats correct...this feature already exists afaik.
Quote Reply
Re: [ridesworld] [Suggestion] Template path change for file includes In reply to
The problem is, that this path is relative to the current template set, even if you can step out from current template root dir with <%include ../includes/header.txt%>.

But you can not use absolute path. That means you can not use the same templates for all services on your site.

You have the following site directory structure:
/cgi-bin/mysite/gforum/
/cgi-bin/mysite/gforum/admin/
/cgi-bin/mysite/gforum/admin/templates/default
/cgi-bin/lsql/
/cgi-bin/lsql/admin/
/cgi-bin/lsql/admin/templates/default
/cgi-bin/myscript/
/cgi-bin/common-templates/

Now, you could use the following tags in category.html template of LSQL:
Code:
<%include /cgi-bin/common-templates/header.txt%> # uses absolute path to include
header from central template directory.

<%include body.txt%> # uses the usual relative path to include the body part from
the current template root directory (/cgi-bin/lsql/admin/templates/default/).

<%include /cgi-bin/common-templates/footer.txt%> # uses absolute path to include
footer from central template directory.


You could use same common template files in forum-view.html template of GForum, too:
Code:
<%include /cgi-bin/common-templates/header.txt%> # uses absolute path to include
header from central template directory.

<%include body.txt%> # uses the usual relative path to include body part from
current template root directory (/cgi-bin/mysite/gforum/admin/templates/default/)

<%include /cgi-bin/common-templates/footer.txt%> # uses absolute path to include
footer from central template directory.


We could use same common templates in our own scripts mytemplate.html template of myscript.cgi, too:
Code:
<%include /cgi-bin/common-templates/header.txt%> # uses absolute path to include
header from central template directory.

<%include mybody.txt%> # uses the usual relative path to include the body part
from the current template root directory (/cgi-bin/myscript/templates/).

<%include /cgi-bin/common-templates/footer.txt%> # uses absolute path to include
footer from central template directory.


If the suggested modification would be done in GT::Template, we could use same common templates sitewide and GT::Template module in our own scripts.
Imagine: we could use the same common templates on the whole site, just from same central template directory.

Therefore, I think this would be very important modification of GT::Template module.

Ridesworld, your solution <%include ../includes/header.txt%> could be still used in your templates, but others like me, could be get more out from the GT::Template possibilities.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: May 8, 2002, 3:32 AM
Quote Reply
Re: [webmaster33] [Suggestion] Template path change for file includes In reply to
>>
<%include /cgi-bin/common-templates/header.txt%> # uses absolute path to include header from central template directory.
<<

But that isn't an absolute path...its relative. Absolute means...

/home/sites/htdocs/cgi-bin/templates/header.txt

You can already do what you are suggesting....ie using common headers/footers.....use:

<%include ../../includes/header.txt%>

...you can use that for your different scripts and it will pickup the same includes directory assuming you have a common structure like:

/cgi-bin/links/admin/templates
/cgi-bin/forum/admin/templates

Last edited by:

Paul: May 8, 2002, 3:35 AM
Quote Reply
Re: [Paul] [Suggestion] Template path change for file includes In reply to
Quote:
But that isn't an absolute path...its relative. Absolute means...
/home/sites/htdocs/cgi-bin/templates/header.txt
Yes, this is true. But I don't see reason to use really absolute paths.
I used the word "absolute" and "relative" to make difference between "relative to the site root" and "relative to the template root". Would be much difficult to introduce my idea...

Yes, you are right, could be possible to use real absolute paths for includes.
Use of "absolute" & use "relative to the site root" would be the same good for me.


But Paul, I don't understand your point. SSI virtual works similar like I suggested, in my posts above. So why are you against this modification?

Virtual SSI include use:
- paths "relative to the site root", if starting with "/"
- paths "relative to the current directory", if not starting "/"

I'm not sure that SSI logic is working exactly like this. I don't have time now to look into the Apache SSI docs. But the basics are similar...

My opinion is, that it would be a useful improvement. Additionally it would not mean to modify or remove any current feature of GT::Template module.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] [Suggestion] Template path change for file includes In reply to
GT staff? Alex? Opinion?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] [Suggestion] Template path change for file includes In reply to
Bringing to the top again.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...