login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Snippets > Kleine toevoeging op TemplatePower

Kleine toevoeging op TemplatePower

Auteur: ikkedikke - 02 augustus 2006 - 15:38 - Gekeurd door: Maarten - Hits: 2929 - Aantal punten: 2.25 (2 stemmen)



het is een klasse waarin ik bij de functie assign enigzins debug-code heb toegevoegd om er snel achter te komen dat een bepaald block niet bestaat.
ook miste ik de functie om de waarde van een globale variabele op te vragen.

in principe kan je deze code gewoon onder de 2e klasse van templatepower plakken.
het enige dat je in je code moet aanpassen is het volgende:
$oLayOut = new TeplatePower('./includes/templates/template.tpl');
wordt:
$oLayOut = new EditedTeplatePower('./includes/templates/template.tpl');

verder spreekt de functie getGlobalValue voor zich.
geeft de waarde van de globale variabele aangemaakt met assignGlobal terug indien die bestaat, anders false.
het gebruik van newBlock is niet veranderd, alleen geeft die nu een error bij een niet bestaand block.

Code:
  1. <?php
  2. class EditedTeplatePower extends TemplatePower
  3. {
  4.  
  5. /**
  6.   * constructor
  7.   *
  8.   * @param string $tpl_file
  9.   * @return
  10. *
  11. * @access public
  12.   */
  13.  
  14. public function __contruct($tpl_file)
  15. {
  16. $this->TemplatePower($tpl_file);
  17. }
  18. /**
  19. * newBlock
  20. *
  21. * @param string $blockname
  22. * @return
  23. *
  24. * @acces public
  25. */
  26.  
  27. public function newBlock( $blockname )
  28. {
  29. if(!isset( $this->parent[$blockname],
  30. $this->parent[$blockname],
  31. $this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ]
  32. )
  33. )
  34. {
  35. trigger_error('TP: het block"'.$blockname.'" is niet gedefinieerd in het templatebestand/subblock');
  36. }
  37. else
  38. {
  39. $parent = &$this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ];
  40. $lastitem = sizeof( $parent );
  41. $lastitem > 1 ? $lastitem-- : $lastitem = 0;
  42. $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
  43. if ( !isset( $parent[ $lastitem ]["_B:$blockname"] ))
  44. {
  45. //ok, there is no block found in the parentblock with the name of {$blockname}
  46. //so, increase the index counter and create a new {$blockname} block
  47. $this->index[ $blockname ] += 1;
  48. $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
  49. if (!isset( $this->content[ $ind_blockname ] ) )
  50. {
  51. $this->content[ $ind_blockname ] = Array();
  52. }
  53. //tell the parent where his (possible) children are located
  54. $parent[ $lastitem ]["_B:$blockname"] = $ind_blockname;
  55. }
  56. //now, make a copy of the block defenition
  57. $blocksize = sizeof( $this->content[ $ind_blockname ] );
  58. $this->content[ $ind_blockname ][ $blocksize ] = Array( $blockname );
  59. //link the current block to the block we just created
  60. $this->currentBlock = &$this->content[ $ind_blockname ][ $blocksize ];
  61. }
  62. }
  63.  
  64. public function getGlobalValue( $varname )
  65. {
  66. return isset($this->globals[ $varname ])? $this->globals[ $varname ] : false;
  67. }
  68. }
  69. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.045s