Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Hook und Smarty Kombination macht Probleme :(

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Paykoman
Smarty Rookie


Joined: 07 May 2011
Posts: 34

PostPosted: Fri Jun 07, 2013 6:08 pm    Post subject: Hook und Smarty Kombination macht Probleme :( Reply with quote

Hallöchen,

wie mansche vllt. wissen bin ich weder in Smarty noch in OOP ein Erfahrener User. Nun habe ich ein neues Problem und habe hier leider noch keine Vorstellung wie ich das lösen soll Sad


Header wird so erstellt...
Code:
public function getHeader($arr){
      
      /* meine inhalte ...  aber es geht eh nur um den Hook.*/

      // header hook
      $smarty->assign("hook_header", $GLOBALS["hook"]->execute_hook('header'), true);
      
      $smarty->display($_SESSION['tpl'].'/'.'header'.tpl_ext);
}


Sodele hier wird dem Script gesagt er soll den header-hook laden, alles was geladen wird, soll in der Variable "hook_header" gespeichert werden und dann an Smarty übergeben werden!
Meine Tests die ich zuvor gemacht habe enthielten aber direkten code wie $return = "<div>blupp mein test</div>"; So davon hatte ich zwei drei Stück um gleichzeitig auch die Positionierung als um die Reihenfolge der Ausgabe zu testen! Dies hat soweit alles fehlerfrei funktioniert!

Nun soll mein Script aber ansatzweise Modul basierend aufgebaut werden und wieder habe ich erst mal einen einfachen test gemacht der wie folgt aussieht:

headbar.modul.php (hier registriert das System das es ein Modul ist und am Ende wird dieses Modul in den Hook geladen)

Code:
class headbar
{
   public function getHB(){
      $smarty = new Smarty;
      $smarty->force_compile = force_compile;
      $smarty->cache_lifetime = cache_lifetime;
      $smarty->debugging = debugging;
      $smarty->caching = caching;
         
      $smarty->assign('headbar_hook', $GLOBALS['hook']->execute_hook('headbar_hook'), true);
      $smarty->assign('posfixed', 'true', true);
         
      $smarty->display('modules/gfw/headbar/headbar'.tpl_ext);
   }
}

$headbar = new headbar();
add_hook( 'header', array(&$headbar,'getHB') );


Die tpl dazu schaut so aus:
Code:
<div id='headbar'>
   {$headbar_hook}
</div>


So das klappt bis hier hin auch alles wunderbar bzw. ob meinesachen später im headbar_hook geladen werden habe ich noch nicht getestet aber sollte klappen (System funktioniert ja xD).

Mein Problem ist viel mehr das Smarty die Ausgabe zerstört und die Templatedatei nicht an der richtigen Stelle einbindet...

So sollte es sein:
Code:
<header>
         <div class="main">
            <div class="wrapper">
               <!-- hook 1 -->
               <nav>
                  <ul class='menu'>
                     <li><a class='active' href='index.html'>Home</a></li>
                     <li><a href='services.html'>Services</a></li>
                     <li><a href='gallery.html'>Gallery</a></li>
                     <li><a href='privacy.html'>Privacy</a></li>
                     <li><a href='contacts.html'>Contacts</a></li>
                  </ul>
               </nav>
               <!-- hook 1 ENDE  -->
               <!-- hook 2 -->
               <div class="ic">Hooktest 2</div>
               <!-- hook 2 ENDE  -->
               <!-- hook 3 -->
               <div id='headbar'>
                  <!-- hier kommt content xD -->
               </div>
               <!-- hook 3 ENDE  -->
            </div>
         </div>
      </header>


Aber jetzt wo die Module keinen html code mehr via php ausgeben und ich dafür eine Tempaltedatei angelegt habe so das eben Smarty integriert ist und jedes Mdoul sein eigene templates verwenden kann zeigt er die hhoks ganz oben an bevor alles andere geladen wird Sad


Code:

<h1>
   <a id='logo' href="http://gfw2day.lo">Your Project</a>
   <strong>Creative Ideas</strong>
</h1><div id='headbar'>
   
</div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
hier kommt dann <head> usw...



Da würde ich mich freuen wenn erfahrene User mich auf einen Fehler hinweisen könnten oder ob ich etwas nicht berücksichtige!
Offensichtlich scheint des ja soweit zu klappen solange mein modul kein eigenes .tpl hat sondern den output in php speichert wie oben beschrieben =(


MFG: Pay[/code]
Back to top
View user's profile Send private message
ovnn
Smarty Regular


Joined: 14 Apr 2010
Posts: 82
Location: Germany

PostPosted: Mon Jun 10, 2013 7:47 am    Post subject: Reply with quote

hab jetzt nur grob geschaut aber display gibt das template direkt zurück. Du musst so was mittels template include machen und nur einmal am ende einen Display absetzen mit einem Struktur template was dann die anderen je nach variable includet.
Back to top
View user's profile Send private message
Paykoman
Smarty Rookie


Joined: 07 May 2011
Posts: 34

PostPosted: Mon Jun 10, 2013 10:24 pm    Post subject: Reply with quote

HuHu,

danke für den tipp, werde mir später mal anschauen wie so ein include aussehen muss, denn Ziel ists es ja blos die zuständige .php datei auszuführen welche dann automatisch das .tpl anspricht und es ausgibt.

Aber nun arbeite ich gerade erstmal daran ein controller system zu integrieren denn dann sollten solche Sachen in Zukunft einfacher zu lösen sein =)


MFG: Paykoman
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP