NickM
Posts: 44
|
Posted: 06/09/2004, 12:13 AM |
|
I would like to include a page, but not the same page each time.
Something like this:
Include page where directory/pagename_of_file_to_include = thispagename.
Any ideas?
|
|
|
ghtracey
Posts: 23
|
Posted: 06/09/2004, 9:46 AM |
|
I have a couple, but being as how I am not sure how you mean to tell the page which include you want. Would you pass it as a parameter, or via some other method?
Try this: in your page HTML, insert:
<?php include("{IncludeFile"); ?>
Then in the BeforeShow event, use:
global $Tpl;
$Tpl->SetVar("IncludeFile","path/to/include");
If the variable is not set soon enough, try in the AfterInitialize or OnInitializeView events.
_________________
Graham Tracey
Council of Yukon First Nations |
|
|
Sixto Luis Santos
|
Posted: 06/09/2004, 11:31 AM |
|
If you are looking for a mechanism to modularize some pages in a way that
allows you to include the page dynamically, then we discussed that topic in
RexDesign a while ago. Look for the thread "Is there any way to change
include file / page on-fly ?" (http://ccs.ath.cx/bb/viewtopic.php?t=55) in
the "CCS Application Questions" forum. Please be aware that you must
register to gain access to the forums.
I don't remember if we posted the proof-of-concept sample app there, but we
modified the Portal application to use modules called from a menu. I can
email you the project if you need it.
Regards,
Sixto
"NickM" <NickM@forum.codecharge> wrote in message
news:540c6b8ab80ce9@news.codecharge.com...
> I would like to include a page, but not the same page each time.
> Something like this:
> Include page where directory/pagename_of_file_to_include = thispagename.
> Any ideas?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
NickM
Posts: 44
|
Posted: 06/09/2004, 6:54 PM |
|
Graham said:
Quote :I have a couple, but being as how I am not sure how you mean to tell the page which include you want. Would you pass it as a parameter, or via some other method?
I was actually thinking of having the name of the file in the dbase with all the other info for each page.
Does that make it any easier to do, or harder?
|
|
|
NickM
Posts: 44
|
Posted: 06/09/2004, 7:04 PM |
|
In the end what I want to do is have the name of the file in the dbase, then call that name and have the actual file (text or HTML) show up in the page.
At the moment the only way to have the text show up is to have it in the database itself - but that makes it difficult to make minor changes to the text compared with having it as a separate file (and only the name is in the dbase).
I thought this might be as easy as say, having the name of an image in the dbase but the actual image shows up in the page - not the name - when the page is created.
|
|
|
Sixto Luis Santos
|
Posted: 06/09/2004, 10:28 PM |
|
That is very easy to do in CCS with some custom code. First, add a label
where you want your dynamic content to appear, set its data source to the
field where the filenames are stored and the content property to HTML. Next,
add some custom code to the label's BeforeShow event:
$fname=$form_name->label_name->GetValue();
if(file_exists($fname)){
$fcontent=file_get_contents($fname);
$form_name->label_name->SetValue($fcontent);
} else {
// Clear label or set an error message or default text
$form_name->label_name->SetVaue("File Not Found");
}
Regards,
Sixto
"NickM" <NickM@forum.codecharge> wrote in message
news:540c7c1ca20612@news.codecharge.com...
> In the end what I want to do is have the name of the file in the dbase,
then
> call that name and have the actual file (text or HTML) show up in the
page.
> At the moment the only way to have the text show up is to have it in the
> database itself - but that makes it difficult to make minor changes to the
text
> compared with having it as a separate file (and only the name is in the
> dbase).
> I thought this might be as easy as say, having the name of an image in the
> dbase but the actual image shows up in the page - not the name - when the
page
> is created.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
NickM
Posts: 44
|
Posted: 06/10/2004, 7:19 AM |
|
Sixto, many thanks, I've almost got it.
Here is the code I use for my example. I think I understood which parts to replace for my example, but it does not quite work. I either get the link to the file, or "not found":
global $ftm1;
// Write your own code here.
$fname=$ftm1->Link1->GetValue();
if(file_exists($fname)){
$fcontent=($fname);
$ftm1->Link1->SetValue($fcontent);
} else {
// Clear label or set an error message or default text
$ftm1->Link1->SetValue("File Not Found");
}
Where the Form name is: ftm1
Link name is: Link1
the data entry in the dbase is: includetxt/file1.html
Any thoughts?
|
|
|
NickM
Posts: 44
|
Posted: 06/10/2004, 7:24 AM |
|
I think the bit I don't understand is this part of your code
$fcontent=file_get_contents($fname);
what should go into "file_g?et_contents"
|
|
|
Sixto Luis Santos
|
Posted: 06/10/2004, 11:29 AM |
|
file_get_contents() is a PHP function to get the content of a file, but it's
only available in PHP 4.3 or better. For previous versions, use fopen/fread.
e.g.:
// Replace $fcontent=file_get_contents($file); with
$fp=fopen($fname,"r");
$fcontent=fread($fp,filesize($fname));
fclose($fp);
So, your code block would be:
global $ftm1;
// Write your own code here.
$fname=$ftm1->Link1->GetValue();
if(file_exists($fname)){
$fp=fopen($fname,"r");
$fcontent=fread($fp,filesize($fname));
fclose($fp);
$ftm1->Link1->SetValue($fcontent);
} else {
// Clear label or set an error message or default text
// Please, for security, change this on your production version...
$ftm1->Link1->SetValue("File Not Found: $fname");
}
"NickM" <NickM@forum.codecharge> wrote in message
news:540c86f3813c71@news.codecharge.com...
> I think the bit I don't understand is this part of your code
> $fcontent=file_get_contents($fname);
> what should go into "file_g?et_contents"
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
NickM
Posts: 44
|
Posted: 06/16/2004, 4:10 AM |
|
Well spotted Sixto,
I'm using 4.2.3
The code presented works perfectly for me.
Many, many thanks.
|
|
|
|