|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
BrainAFK Smarty n00b
Joined: 22 Feb 2014 Posts: 4
|
Posted: Sat Feb 22, 2014 9:13 am Post subject: Variable im Template überschreiben |
|
|
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}&page=last#last_post">
{/foreach}
|
Diesen Link würde ich gerne abändern als
Code: | <a href="{$fval.forum_last_topic_id}&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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
BrainAFK Smarty n00b
Joined: 22 Feb 2014 Posts: 4
|
Posted: Wed Feb 26, 2014 3:15 pm Post subject: |
|
|
Code: | Fatal error: Call to undefined method Smarty::registerFilter() in C:\xampp\htdocs\point\.......... |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
BrainAFK Smarty n00b
Joined: 22 Feb 2014 Posts: 4
|
Posted: Thu Feb 27, 2014 11:36 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 27, 2014 12:13 pm Post subject: |
|
|
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 |
|
|
|
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
|