[PHP] Vullen van template variabele - waar kijk ik overheen?

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
Ik ben bezig met mijn eigen websiteje en werk op de volgende manier.

template.php --> bevat html met pagina layout. en $tpl_variabelen. Voorbeeld:
PHP:
1
2
3
4
5
6
7
8
9
<html>
  <head>
    <title><?= $tpl_title; ?></title>
  <?= $tpl_head; ?>
  </head>
<body>
  <?= $tpl_body; ?>
</body>
</html>


Daarnaast heb ik mijn PHP scripts waar de lay-out variabelen gevuld worden. Bijvoorbeeld:
PHP:
1
2
3
$res_title = db_query('SELECT title FROM pages WHERE node_id = '.$_GET['id']);
$row_conts = db_fetch_array($res_conts);
$tpl_title = $row_conts['title']; // stuur naar template


Nu heb ik een html editor gedownload waarmee ik in de browser content kan editten. Een mooi stukje software (http://www.fredck.com/FCKeditor/) en je moet het op de volgende manier aanroepen:
PHP:
1
2
3
4
5
$oFCKeditor = new FCKeditor ;
$oFCKeditor->BasePath = '/mijn/website/pad/editor/' ;
$oFCKeditor->ToolbarSet = 'Minimal' ;
$oFCKeditor->Value = 'Text die in het iframe verschijnt' ;
$oFCKeditor->CreateFCKeditor( 'EditorDefault', '100%', 450 ) ;


Dus ik probeer dit nu al een tijdje in mijn PHP script in te voegen:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$tpl_body .= '<form name="contents" action="_edit.php" method="post">.
             '<input type="hidden" name="text" value="">'.
             '<table cellspacing="0" cellpadding="3" border="0">'.
             '<tr><td colspan="2">';
             include('editor/fckeditor.php');
             $oFCKeditor = new FCKeditor;
             $oFCKeditor->BasePath = '/mijn/website/pad/editor/';
             $oFCKeditor->ToolbarSet = 'Custom';
             $oFCKeditor->Value = 'hoi';
             $oFCKeditor->CreateFCKeditor( 'Editortext', '100%', 450 );
$tpl_body .= '</td></tr>'.
             '<tr><td colspan="2" align="right">'.
             '<input type="button" onclick="do_submit();" value="Opslaan">'.
             '</td></tr></table></form>';


Maar nu zet hij die editor niet neer op de plaats waar ik wil. De html output van bovenstaande ziet er als volgt uit:

HTML:
1
2
3
4
5
6
7
8
9
10
11
<IFRAME src="/odisys/new2/beta/admin/editor/fckeditor.html?
FieldName=Editortext&Toolbar=Custom" width="100%" height="450"
frameborder="no" scrolling="no"></IFRAME><INPUT type="hidden"
name="Editortext" value="hoi"> <!------ output van de editor class. 
Is goed, maar staat verkeerd!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
...


Met andere woorden: hij runt eerst die editor en daarna wordt pas de rest van de PHP geparsed. Als oplossing heb ik zaken geprobeerd als
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$tpl_body .= '<form name="contents" action="_edit.php" method="post">.
             '<input type="hidden" name="text" value="">'.
             '<table cellspacing="0" cellpadding="3" border="0">'.
             '<tr><td colspan="2">';
             include('editor/fckeditor.php');
$tpl_body .= $oFCKeditor = new FCKeditor;
$tpl_body .= $oFCKeditor->BasePath = '/mijn/website/pad/editor/';
$tpl_body .= $oFCKeditor->ToolbarSet = 'Custom';
$tpl_body .= $oFCKeditor->Value = 'hoi';
$tpl_body .= $oFCKeditor->CreateFCKeditor( 'Editortext', '100%', 450 );
$tpl_body .= '</td></tr>'.
             '<tr><td colspan="2" align="right">'.
             '<input type="button" onclick="do_submit();" value="Opslaan">'.
             '</td></tr></table></form>';


Maar dit haalt niets uit. En dat snap ik niet. In de zipfile die ik gedownload heb dit het volgende werkende voorbeeld van hoe je de editor kunt integreren in je pagina:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <TITLE>FCKeditor - PHP Test Page</TITLE>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
  </HEAD>
<BODY>
  <form action="testsubmit.php" target="_blank" method="post" language="javascript">
<?php
$oFCKeditor = new FCKeditor ;
$oFCKeditor->BasePath = '/FCKEditor/' ;
$oFCKeditor->ToolbarSet = 'Custom' ;
$oFCKeditor->Value = 'hello world!' ;
$oFCKeditor->CreateFCKeditor( 'EditorDefault', '100%', 450 ) ;
?>
    <INPUT type="submit" value="Submit Data">
  </form>
</BODY>
</HTML>


Dit werkt wel. Maar zoals aangegeven bouw ik de hele html output op binnen <?php tags ?>. Ik weet zeker dat de oplossing heel simpel is, maar ik kom er maar niet op }:O Wie helpt mij op weg?

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Reveller schreef op 08 mei 2004 @ 18:34:
Met andere woorden: hij runt eerst die editor en daarna wordt pas de rest van de PHP geparsed. Als oplossing heb ik zaken geprobeerd als
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$tpl_body .= '<form name="contents" action="_edit.php" method="post">.
             '<input type="hidden" name="text" value="">'.
             '<table cellspacing="0" cellpadding="3" border="0">'.
             '<tr><td colspan="2">';
             include('editor/fckeditor.php');
$tpl_body .= $oFCKeditor = new FCKeditor;
$tpl_body .= $oFCKeditor->BasePath = '/mijn/website/pad/editor/';
$tpl_body .= $oFCKeditor->ToolbarSet = 'Custom';
$tpl_body .= $oFCKeditor->Value = 'hoi';
$tpl_body .= $oFCKeditor->CreateFCKeditor( 'Editortext', '100%', 450 );
$tpl_body .= '</td></tr>'.
             '<tr><td colspan="2" align="right">'.
             '<input type="button" onclick="do_submit();" value="Opslaan">'.
             '</td></tr></table></form>';
Dit klopt alvast niet, zoals je aan de syntax highlighting al kunt zien. Verder komt het mij heel erg vreemd over om PHP te schrijven naar een template, maar je zal je redenen wel hebben.

Ik zou in ieder geval de maker van die editor eens mailen, of kijken of die een FAQ of forum heeft, want ik denk niet dat wij je hier echt mee kunnen helpen. Succes in ieder geval. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • lost95
  • Registratie: Januari 2000
  • Laatst online: 18:01
Een, ik denk geen nette oplossing:, laat die editorcode in een eigen bestandje. Dus iets van:
PHP:
1
2
3
4
5
6
7
8
editor.php:
<?
$oFCKeditor = new FCKeditor ; 
$oFCKeditor->BasePath = '/mijn/website/pad/editor/' ; 
$oFCKeditor->ToolbarSet = 'Minimal' ; 
$oFCKeditor->Value = 'Text die in het iframe verschijnt' ; 
$oFCKeditor->CreateFCKeditor( 'EditorDefault', '100%', 450 ) ;
?> 


en dan in je page waar je je editor wil hebben:
PHP:
1
include('editor.php');

Vooral sinaasappels zijn bang voor persvrijheid.


Acties:
  • 0 Henk 'm!

  • PrisonerOfPain
  • Registratie: Januari 2003
  • Laatst online: 26-05 17:08
NMe84 schreef op 08 mei 2004 @ 21:19:
[...]

Dit klopt alvast niet, zoals je aan de syntax highlighting al kunt zien.
Er is alleen een ' vergeten aan het eind van de eerste regel ;)

Acties:
  • 0 Henk 'm!

  • _Gekkie_
  • Registratie: Oktober 2000
  • Laatst online: 24-06 20:21

_Gekkie_

And the cow said: Helloooooow?

Is het niet probleem niet veel simpeler? Namelijk dat de output van de php functie welke de editor opbouwd ($oFCKeditor->CreateFCKeditor) gelijk redirect naar het scherm ipv naar je ($tpl_body) ?

Overigens redirect je de output zowieso niet :) Misschien ligt het daar ook wel aan?

Gekkie is a proud member of TheBenny!


Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

PrisonerOfPain schreef op 09 mei 2004 @ 16:46:
[...]

Er is alleen een ' vergeten aan het eind van de eerste regel ;)
I know, dat is wat ik bedoelde. :P

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • jan-marten
  • Registratie: September 2000
  • Laatst online: 20-09 15:31
PHP:
1
2
$tpl_editor = $oFCKeditor->ReturnFCKeditor( 'EditorDefault', '100%', 450 ) 
print $tpl_editor; // waar je maar wilt
Pagina: 1