| View previous topic :: View next topic |
| Author |
Message |
iranmehr Smarty Rookie

Joined: 01 Nov 2005 Posts: 5
|
Posted: Thu Nov 10, 2005 2:34 pm Post subject: Dynamic publishing (in MT) & using php in entries |
|
|
Hi,
At first I posted my question (below) to Movable Type forum, but I did not get any answer.
I want to use php script in the posts of my weblog that published dynamically. The Smarty does not parse the php code that is within an entry.
How can I tell to Smarty that parses the php code inside of content of an entry?
Thank you. _________________ iran - mithras |
|
| Back to top |
|
 |
iranmehr Smarty Rookie

Joined: 01 Nov 2005 Posts: 5
|
Posted: Tue Dec 06, 2005 3:40 pm Post subject: |
|
|
Maybe I did not explain very clear my problem in first post that no one answers me!
You know that in Movable Type we can publish our entries dynamically - based on Smarty ability.
It may happen that I wanted use a php script in my entry content.
| Code: | | This is a <?php if ($x == 'red') { echo $x; } else { echo 'golden'; } ?> fish. |
The script works in static publishing, but in dynamic publishing the code does not parse and shown in generated page. Like that the code printed through single quotes:
| Code: | | echo 'This is a <?php if ($x == \'red\') { echo $x; } else { echo \'golden\'; } ?> fish.'; |
Also the codes that content of an entry published by them are these:
| Code: | | <?php echo smarty_function_MTEntryBody(array(), $this);?> | and | Code: | | <?php echo smarty_function_MTEntryMore(array(), $this);?> | for extended entry.
Is there any key to this problem or I must find another way for my will?
I appreciate of every idea and help.
Thanks. _________________ iran - mithras
Last edited by iranmehr on Tue Dec 06, 2005 8:48 pm; edited 1 time in total |
|
| Back to top |
|
 |
boots Administrator
Joined: 16 Apr 2003 Posts: 5610 Location: Toronto, Canada
|
Posted: Tue Dec 06, 2005 6:48 pm Post subject: |
|
|
| I don't know much about MT but I know that with Smarty, allowing php codeblocks can be configured. Assuming defaults, Smarty will let you insert a PHP codeblock using the {php}...{/php} tag. If this does not work, then MT has enabled Smarty's security mode. In either case, including php codeblocks directly in your template is actually discouraged; it is better to refactor the code into a custom plugin and rather use that instead. |
|
| Back to top |
|
 |
iranmehr Smarty Rookie

Joined: 01 Nov 2005 Posts: 5
|
Posted: Tue Dec 06, 2005 8:48 pm Post subject: |
|
|
Thanks for your answer.
I used what you said, but result was alike before.
Therefore I checked the files in php directory of MT. In "Smarty.class.php", security set to false: | Code: | | var $security = false; |
Besides, I have not any problems with php codes in templates of MT. My problem back to what I write in a post. As like as I want to use my code between of these lines. Although, here it does not allowed. _________________ iran - mithras |
|
| Back to top |
|
 |
boots Administrator
Joined: 16 Apr 2003 Posts: 5610 Location: Toronto, Canada
|
Posted: Tue Dec 06, 2005 9:25 pm Post subject: |
|
|
Does this work?
| Code: | | This is a {php} if ($x == 'red') { echo $x; } else { echo 'golden'; } {/php} fish. |
(of course, $x is unknown here, I'm just wondering if this gets executed or not) |
|
| Back to top |
|
 |
iranmehr Smarty Rookie

Joined: 01 Nov 2005 Posts: 5
|
Posted: Wed Dec 07, 2005 4:57 am Post subject: |
|
|
No, it did not work. Even it does not work on MT templates, unless using them like this: {{php}}…{{/php}}. (This one does not work on entries, too.)
The code I write here is an example. In fact I get the value from a cookie that has set or has not set already by the visitor: | Code: | | ($_COOKIE['imageEnabled'] == 'disabled') | If it has set 'disabled' my weblog images will not loaded, else they checked if they are available on the web and then loaded.
I did not write my code because it is a very plain and rude one, such as my example.  _________________ iran - mithras |
|
| Back to top |
|
 |
boots Administrator
Joined: 16 Apr 2003 Posts: 5610 Location: Toronto, Canada
|
Posted: Wed Dec 07, 2005 6:08 am Post subject: |
|
|
Sorry, it seems my knowledge of MT's use of Smarty is too limited to be helpful here.
Good Luck! |
|
| Back to top |
|
 |
iranmehr Smarty Rookie

Joined: 01 Nov 2005 Posts: 5
|
Posted: Wed Dec 07, 2005 7:42 am Post subject: |
|
|
Thank you. Your answer was helpful for me, because I now know what I want to do is possible and I learn a bit about security variable in Smarty.
Good luck, too. _________________ iran - mithras |
|
| Back to top |
|
 |
|