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

Variable im Template überschreiben

 
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
BrainAFK
Smarty n00b


Joined: 22 Feb 2014
Posts: 4

PostPosted: Sat Feb 22, 2014 9:13 am    Post subject: Variable im Template überschreiben Reply with quote

Hallo,

ich beschäftige mich seit Jahren schon mit PHP/SQL.
Nun will ich gerne alles auf die Smarty Engine stellen. Stoße aber noch auf ein Problem.

Ist es möglich einen Wert in der*.htm Datei via PHP zu überschreiben?

In der htm Datei befindet sich

Code:
{foreach from=$FORUM_LISTR key=fkey item=fval name=forumlist}
<a href="{$U_TOPIC}?t={$fval.forum_last_topic_id}&amp;page=last#last_post">
{/foreach}

Diesen Link würde ich gerne abändern als

Code:
<a href="{$fval.forum_last_topic_id}&amp;page=last#last_post">


Ich weiss gerade nicht ob dies überhaupt möglich ist.
Im Normalfall würde ich einfach die htm File dementsprechend abändern, habe aber aufgrund der unfähigkeit eines mitentwicklers keinen direkten Zugriff auf die htm file wodurch ich auf PHP zurückgreifen muss.


EDIT:
Mir fällt gerade ein, wenn es so über Smarty selber nicht geht, könnte man doch die entsprechende index.htm File einlesen, sich diese Textzeile rauspicken und ersetzen?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Feb 23, 2014 9:34 am    Post subject: Reply with quote

Siehe http://www.smarty.net/docs/en/advanced.features.prefilters.tpl

Mit dem prefilter kannst Du das Template Source verändern bevor Smarty es compiliert.
Back to top
View user's profile Send private message
BrainAFK
Smarty n00b


Joined: 22 Feb 2014
Posts: 4

PostPosted: Wed Feb 26, 2014 3:15 pm    Post subject: Reply with quote

Code:
Fatal error: Call to undefined method Smarty::registerFilter() in C:\xampp\htdocs\point\..........
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Feb 26, 2014 8:36 pm    Post subject: Reply with quote

Kann es sein dass Du noch Smarty2 benutzt?

Dann siehe http://www.smarty.net/docsv2/en/api.register.prefilter.tpl
Back to top
View user's profile Send private message
BrainAFK
Smarty n00b


Joined: 22 Feb 2014
Posts: 4

PostPosted: Thu Feb 27, 2014 11:36 am    Post subject: Reply with quote

Genau, ich nutze noch die 2er bzw. das Forum welches ich benutze.

Habe im Netz dank deiner Hilfe nun folgendes gefunden

Code:
function remove_html_comments($source, &$smarty)
{
// remove any html comments from the template source, even
// if they span multiple lines
return preg_replace('/<!--.*-->/Ums', '', $source);
}
$smarty->register_prefilter('remove_html_comments');
$smarty->load_filter('output', 'trimwhitespace');


Dazu gab es keine nähere Beschreibung. Ich gehe davon aus das damit Kommentare im HTML Code entfernt werden bzw. durch ein leerzeichen ersetzt werden. Ich habe es angewendet, aber ohne erfolg. Vorallem was die letzte Zeile betrifft ist mir unklar.


Der ganze Code sieht bei mir so aus

Code:
function remove_html_comments($source, &$Smarty)
{
// remove any html comments from the template source, even
// if they span multiple lines
return preg_replace('<!--#.*-->/U', '', $source);
}
$Smarty->register_prefilter('remove_html_comments');
$Smarty->load_filter('output', 'trimwhitespace');
      $Smarty->assign(array(
            'HYPERLINK'         => HYPERLINK,
            'U_INDEX'         => 'index.' . EXT,
         ));
      
      $Smarty->display('index.htm');
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Feb 27, 2014 12:13 pm    Post subject: Reply with quote

Ein Prefilter wirkt nur beim Kompilieren des Templates.

Wenn Du ein Prefilter einführst oder modifizierst musst Du die Dateien im template_c und cache Verzeichniss löschen damit sie unter Anwendung des Filters wieder neu erzeugt werden.
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