Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Templates > Smarty
Smarty Forum d'entraide sur le moteur de templates Smarty. Avant de poster -> FAQ Smarty et Cours Smarty
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 13/12/2007, 11h00   #1
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
Par défaut Mon code PHP n'est pas interprété

Bonjour,


Totalement novice sur smarty j'ai voulu insérer du code PHP dans mon template (je sais que c'est le comble et que c'est justement pas le but de smarty).

Code :
1
2
3
{php}
echo 'Test';
{/php}
Je vois afficher {php} echo 'Test'; {/php} y a-t-il quelque chose de particulier à faire pour qu'il soit interprété.

Merci
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2007, 11h55   #2
Rédacteur
 
Avatar de Yoteco
 
Alain Sahli
Ingénieur développement logiciels
Inscription : décembre 2004
Messages : 1 086
Détails du profil
Informations personnelles :
Nom : Alain Sahli
Âge : 25

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : décembre 2004
Messages : 1 086
Points : 1 479
Points : 1 479
Salut, est-ce que tu fais bien

Code :
$smarty->display('ta_template.tpl');
Et dans ta_template.tpl tu as tes balises {php} ?
Yoteco est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2007, 12h03   #3
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
Code :
$preproc->display( "catalog_resizable.htm" );
Et dans la page catalog_resizable.htm

Code :
<? assign var=rightPanelContent value="../../../DD/html/classic/filelist.htm" ?>
Mon template avec le code PHP est dans filelist.htm
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2007, 13h58   #4
Rédacteur
 
Avatar de Yoteco
 
Alain Sahli
Ingénieur développement logiciels
Inscription : décembre 2004
Messages : 1 086
Détails du profil
Informations personnelles :
Nom : Alain Sahli
Âge : 25

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : décembre 2004
Messages : 1 086
Points : 1 479
Points : 1 479
Alors à ce moment là tu dois utiliser la fonction include de smarty. Je te laisse aller lire la doc.
Yoteco est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2007, 16h13   #5
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
Même si je fais ça directement, ça ne fonctionne toujours pas, mon PHP n'est pas interprété.

Code :
$preproc->display( "filelist.htm");
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2007, 18h28   #6
Rédacteur
 
Avatar de Yoteco
 
Alain Sahli
Ingénieur développement logiciels
Inscription : décembre 2004
Messages : 1 086
Détails du profil
Informations personnelles :
Nom : Alain Sahli
Âge : 25

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : décembre 2004
Messages : 1 086
Points : 1 479
Points : 1 479
Montre nous ton fichier filelist.htm parce que moi je viens d'essayer et ça marche sans problèmes avec les tag {php}.
Yoteco est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2007, 09h09   #7
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<? if $viewMode == 0 ?>
	<!-- Grid mode view -->
 
	<table class="Grid" id='FilesTable'>
		<thead>
			<tr>
					<? if $numFiles ?>
						<th align="left" width="10px" style="width: 10px;"><input type="checkbox" name="selectAllDocsCB" onClick="treeSelectAll(this)"></th>
					<? /if ?>
					<? if $versionControlEnabled ?>
						<th align="left" width="16px" style="width: 16px"><img src="../../../DD/html/cssbased/images/lock.gif" ></th>
					<? /if ?>
					<th align="left"><? wbs_sortColumn ajax=true status=$sorting field="DL_FILENAME" ?><? $ddStrings.dd_screen_namesorting_title ?><? /wbs_sortColumn ?></th>
					<? if $searchString != "" ?>
						<th align="left"><? wbs_sortColumn ajax=true status=$sorting field="DF_NAME" ?><? $ddStrings.app_folder_field ?><? /wbs_sortColumn ?>
					</th>
					<? /if ?>
 
					<? foreach from=$visibleColumns item=columnID ?>
						<? assign var=nameIndex value=$dd_columnNames[$columnID] ?>
						<? assign var=columnName value=$ddStrings[$nameIndex] ?>
						<th <? if $columnID != "DL_FILESIZE" ?>align=left<? else ?>align=right<? /if ?>>
							<? wbs_sortColumn ajax=true status=$sorting field=$columnID ?><? $columnName ?><? /wbs_sortColumn ?>
						</th>
					<? /foreach ?>
 
					<? if $numFiles && ($curFolderData->TREE_ACCESS_RIGHTS > 0 ||  $searchString != "") ?>
						<th align="left" width=12>&nbsp;</th>
					<? /if ?>
			</tr>
		</thead>
		<tbody>
			<? foreach from=$files item=file name=fileLoop ?>
				<tr class="<? wbs_oddItem index=$smarty.foreach.fileLoop.iteration ?>">
					<? if $numFiles ?>
						<td align=left valign=top width="10px" style="width: 10px"><input class='Filename' type="checkbox" name="document[<? $file.DL_ID ?>]" value="<? $file.DL_ID ?>" filename='<? $file.DL_FILENAME ?>' filesize='<? $file.DL_FILESIZE_BYTES ?>'  checkstatus='<? if $versionControlEnabled && $file.DL_CHECKUSERID != $currentUser && $file.DL_CHECKSTATUS == "OUT" ?>1<? else ?>0<? /if ?>'><input type=hidden name="filerights[<?$file.DL_ID?>]" value="<? $file.TREE_ACCESS_RIGHTS ?>"></td>
					<? /if ?>
					<? if $versionControlEnabled ?>
						<td align="left" width="16px" style="width: 16px"><? if $file.DL_CHECKSTATUS == "OUT" ?><img title="<? $file.CHECKOUTMESSAGE|htmlsafe:true:true ?>" src="../../../DD/html/cssbased/images/lock.gif" ><? else ?>&nbsp;<? /if ?></td>
					<? /if ?>
					<td align=left valign=top>
					<!-- thumbnail -->
					<? if $displayIcons ?>
						<a href="<? $file.ROW_URL ?>" target="_blank"><img src="<? thumbnail fileName=$file.DL_FILENAME size=16 os=win ?>"  border="0" align=left></a>
					<? /if ?>
 
					<!-- file name -->
					<a href="<? $file.ROW_URL ?>" target="_blank"><? $file.DL_FILENAME|htmlsafe:true:true|sureecho|trunc_str:50 ?></a></td>
					<? if $searchString != "" ?>
						<td align=left valign=top><a href="<? $file.FOLDER_URL ?>" title="<? $ddStrings.dd_screen_openfld_hint ?>"><? $file.DF_NAME|htmlsafe:true:true|sureecho ?></a></td>
					<? /if ?>
 
					<? foreach from=$visibleColumns item=columnID ?>
						<td <? if $columnID != "DL_FILESIZE" ?>align=left<? else ?>align=right<? /if ?> valign=top>
							<? if $columnID != "DL_DESC" ?>
								<? $file.$columnID|htmlsafe:true:true|sureecho ?>
							<? else ?>
								<? if $restrictDescLen ?>
									<? assign var=DESC_LEN value=$file.$columnID|htmlsafe:true:true|strlen ?>
									<span><? $file.$columnID|htmlsafe:true:true|sureecho|trunc_str:$restrictDescLen ?></span>
									<? if $DESC_LEN > $restrictDescLen ?>
										[<a class=activelink href="<? $file.VIEW_DESC_URL ?>"><? $ddStrings.dd_screen_more_label ?></a>]
									<? /if ?>
								<? else ?>
									<? $file.$columnID|htmlsafe:true:true|sureecho ?>
								<? /if ?>
							<? /if ?>
						</td>
					<? /foreach ?>
					<? if $numFiles && ($curFolderData->TREE_ACCESS_RIGHTS > 0 || $searchString != "") ?>
						<td align=left align=center valign=top width=12>
							<? if $numFiles ?>
								CCC <a href=<? $file.DESC_URL ?> title="<? $ddStrings.dd_screen_fileproperties_hint ?>"><img src="../../../common/html/cssbased/res/images/property.gif" border="0" width="17" height="11" style="margin-top: 4px" border=0></a>
							<? else ?>
								&nbsp;
							<? /if ?>
							</td>
					<? /if ?>
				</tr>
		<? foreachelse ?>
			<tr class="NoRecords">
				<? if $searchString != "" ?>
					<td colspan="<? $numColumns ?>" class="default"><? $ddStrings.dd_screen_nofiles_text|htmlsafe:true:true ?></td>
				<? else ?>
					<td colspan="<? $numColumns ?>" class="default"><? $ddStrings.dd_screen_nofiles_text|htmlsafe:true:true ?></td>
				<? /if ?>
			</tr>
		<? /foreach ?>
		</tbody>
	</table>
<? elseif $viewMode == 1 || $viewMode == 2 || $viewMode == 3 ?>
	<table class="List">
			<? if $viewMode == 1 || $viewMode == 2 ?>
				<!-- List view -->
				<? foreach from=$files item=file name=fileLoop ?>
				<tr>
					<td width="10" >
						<input type="checkbox" name="document[<? $file.DL_ID ?>]" value="<? $file.DL_ID ?>" filename='<? $file.DL_FILENAME ?>' filesize='<? $file.DL_FILESIZE_BYTES ?>' checkstatus='<? if $versionControlEnabled && $file.DL_CHECKUSERID != $currentUser && $file.DL_CHECKSTATUS == "OUT"?>1<? else ?>0<? /if ?>'>
						<input type=hidden name="filerights[<?$file.DL_ID?>]" value="<? $file.TREE_ACCESS_RIGHTS ?>">
					</td>
					<td width="32">
						<? if $viewMode == 1 ?>
								<? if $displayIcons ?>
									<a href="<? $file.ROW_URL ?>" target="_blank"><img border=0 style="margin-right: 5px; margin-top: 5px" src="<? thumbnail fileName=$file.DL_FILENAME size=32 os=win ?>" align=absmiddle></a>
								<? /if ?>
							<? else ?>
								<? wbs_thumbnail src=$file.THUMB_URL URL=$file.ROW_URL target='_blank' ?>
							<? /if ?>
					</td>
					<td>
						<table class="ListItem">
						<thead>
							<tr>
								<th scope="col" class="<? $subscrClass ?>">
									<a href="<? $file.ROW_URL ?>" target="_blank"><? $file.DL_FILENAME|htmlsafe:true:true|sureecho|trunc_str:50 ?></a>
									<? if $numFiles ?>
										DDDD <a href=<? $file.DESC_URL ?>><img title="<? $ddStrings.dd_screen_fileproperties_hint ?>" src="../../../common/html/cssbased/res/images/property.gif" border="0" width="17" height="11" style="margin-top: 4px" border=0></a>
									<? /if ?>    
                                </th>
							</tr>
						</thead>
						<tbody>
							<? if $numVisibleColumns ?>
									<tr>
										<td class="treeDocumentListViewContent">
											<? if $file.DL_DESC && $descriptionVisible ?>
												<div style="border-bottom: 1px solid #CCCCCC; margin-right: 5px; padding-bottom: 5px; margin-bottom: 5px; padding-top: 5px; ">
													<? if $restrictDescLen ?>
														<? assign var=DESC_LEN value=$file.DL_DESC|htmlsafe:true:true|strlen ?>
														<span><? $file.DL_DESC|htmlsafe:true:true|sureecho|trunc_str:$restrictDescLen ?></span>
														<? if $DESC_LEN > $restrictDescLen ?>
															[<a class=activelink href="<? $file.VIEW_DESC_URL ?>"><? $ddStrings.dd_screen_more_label ?></a>]
														<? /if ?>
													<? else ?>
														<? $file.DL_DESC|htmlsafe:true:true|sureecho ?>
													<? /if ?>
												</div>
											<? /if ?>
 
											<? foreach from=$visibleColumns item=columnID name=columnLoop ?>
												<? if $columnID != "DL_DESC" && $columnID != "DL_MODIFYUSERNAME" && $columnID != "DL_MODIFYDATETIME" ?>
													<? assign var=nameIndex value=$dd_columnNames[$columnID] ?>
													<? assign var=columnName value=$ddStrings[$nameIndex] ?>
 
                                                    {php}
                                                       echo 'Super';
                                                    {/php}
 
                                                    <? if $columnID == "DL_INDEX" && $file.$columnID != "NULL" ?>
                                                   		<div style="margin-left:25px; padding:3px 0 3px 0;"><strong>Extrait :</strong>
                                                    <? /if ?>
 
                                                        <? if $file.$columnID != "NULL" ?>
                                                         	<? if $columnID == "DL_INDEX" ?>
                                                            	<? $file.$columnID|htmlsafe:true:true|sureecho ?>
                                                            <? else ?>
                                                            	<? $columnName|cat:" : "|cat:$file.$columnID|htmlsafe:true:true|sureecho ?>
                                                            <? /if ?>
 
                                                            <? if $smarty.foreach.columnLoop.iteration < $numVisibleColumns ?>&nbsp;<? /if ?>
                                                        <? else ?>
                                                            <? $columnName|cat:":&nbsp;-&nbsp;"?>
                                                        <? /if ?>
 
                                                    <? if $columnID == "DL_INDEX" && $file.$columnID != "" ?>
                                                   		</div>
                                                    <? /if ?>
 
												<? /if ?>
											<? /foreach ?>
										</td>
									</tr>
									<? if $versionControlEnabled && $file.DL_CHECKSTATUS == "OUT"?>
									<tr>
											<td align="left" class="treeDocumentListViewContent">
													<? if $file.DL_CHECKSTATUS == "OUT" ?>
														<img align=absmiddle title="<? $file.CHECKOUTMESSAGE|htmlsafe:true:true ?>" src="../../../DD/html/cssbased/images/lock.gif" >
														<? $file.CHECKOUTMESSAGE|htmlsafe:true:true ?>
													<? else ?>&nbsp;<? /if ?>
											</td>
									</tr>
									<? /if ?>
							<? /if ?>
						</tbody>
						</table>
					</td>
					</tr>
				<? foreachelse ?>
					<tr class="NoRecords">
						<td align="center" class="default"><? $ddStrings.dd_screen_nofiles_text|htmlsafe:true:true ?></td>
					</tr>
				<? /foreach ?>
			<? /if ?>
		</table>
	<? if $viewMode == 3 ?>
		<? foreach from=$files item=file name=fileLoop ?>
 
			<div style="float: left; width: 110px; height: 160px; padding: 0 0 0 5px">
 
					<? if $restrictDescLen ?>
						<? assign var=truncDesc value=$file.DL_DESC|htmlsafe:true:true|trunc_str:$restrictDescLen ?>
					<? else ?>
						<? assign var=truncDesc value=$file.DL_DESC|htmlsafe:true:true|trunc_str ?>
					<? /if ?>
 
					<? assign var=thumbTitle value=$file.DL_FILENAME|cat:". "|cat:$file.DL_FILESIZE|htmlsafe:true:true?>
					<? if $truncDesc != "" ?>
						<? assign var=thumbTitle value=$thumbTitle|cat:". "|cat:$truncDesc ?>
					<? /if ?>
 
					<? wbs_thumbnail src=$file.THUMB_URL URL=$file.ROW_URL target='_blank' ?>
 
					<div style="padding-top: 1px" class=smallFont align=left>
 
						<table cellpadding=0 cellspacing=0 border=0 width="110">
							<tr>
								<td width=12 valign=middle><input type="checkbox" name="document[<? $file.DL_ID ?>]" value="<? $file.DL_ID ?>" filename='<? $file.DL_FILENAME ?>' filesize='<? $file.DL_FILESIZE_BYTES ?>'  checkstatus='<? if $versionControlEnabled && $file.DL_CHECKUSERID != $currentUser && $file.DL_CHECKSTATUS == "OUT"?>1<? else ?>0<? /if ?>'><input type=hidden name="filerights[<?$file.DL_ID?>]" value="<? $file.TREE_ACCESS_RIGHTS ?>"></td>
								<td align=center valign=middle><nobr>
									<? if $file.DL_CHECKSTATUS == "OUT" ?>
										<img align=absmiddle title="<? $file.CHECKOUTMESSAGE|htmlsafe:true:true ?>" src="../../../DD/html/cssbased/images/lock.gif" >
									<? /if ?>
								<small><a target="_blank" href="<?$file.ROW_URL?>" class=activelink><? $file.DL_FILENAME|truncate:10:"..."|htmlsafe:true:true ?></a></small></nobr></td>
							</tr>
							<tr>
								<? if $numFiles ?>
									<td width=12><a title="<? $ddStrings.dd_screen_fileproperties_hint ?>" href=<? $file.DESC_URL ?>><img src="../../../common/html/cssbased/res/images/property.gif" border="0" width="17" height="11" style="margin-left: 3px; margin-top: 4px" border=0></a></td>
								<? /if ?>
								<td class="AlignCenter"<? if !($numFiles && $file.TREE_ACCESS_RIGHTS > 0) ?>colspan=2<? /if ?>><small><? $file.DL_FILESIZE ?></small></td>
							</tr>
						</table>
					</div>
 
			</div>
 
		<? foreachelse ?>
			<div style="width: 100%" align=center class="NoRecords"><? $ddStrings.dd_screen_nofiles_text|htmlsafe:true:true ?></div>
		<? /foreach ?>
	<? /if ?>
<? /if ?>
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2007, 09h12   #8
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
De toute façon, même si je ne mets que ça dans le fichier ça fonctionne pas.

Code :
1
2
3
{php}
echo 'Super';
{/php}
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/12/2007, 15h49   #9
Membre régulier
 
Inscription : avril 2003
Messages : 335
Détails du profil
Informations forums :
Inscription : avril 2003
Messages : 335
Points : 82
Points : 82
Voici la réponse que j'ai trouvé en postant sur le forum officiel.

Bon c'est tout con mais lorsque l'on connait pas on peut chercher des erreurs et rester bloquer bêtement.

Code :
1
2
3
<?php?>
 echo 'Test';
 <?/php?>

Je m'étais pourtant appuyé sur la documentation : http://smarty.php.net/manual/fr/lang...nction.php.php

Citation:
Les balises {php} permettent de rajouter du code PHP directement dans le template. Ils ne seront pas ignorés, quelle que soit la valeur de $php_handling. Pour les utilisateurs avancés seulement, son utilisation n'est normalement pas nécessaire et n'est pas recommandée.

Exemple 7-28. Exemple avec la balise {php}

Code :
1
2
3
4
{php}
   // inclusion directe d'un script PHP depuis le template.
   include('/chemin/vers/display_weather.php');
{/php}
Si ça peut éviter à d'autre de chercher.
dorian53 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h28.


 
 
 
 
Partenaires

Hébergement Web