Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Dynamic publishing (in MT) & using php in entries

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
iranmehr
Smarty Rookie


Joined: 01 Nov 2005
Posts: 5

PostPosted: Thu Nov 10, 2005 2:34 pm    Post subject: Dynamic publishing (in MT) & using php in entries Reply with quote

Hi, Smile


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
View user's profile Send private message
iranmehr
Smarty Rookie


Joined: 01 Nov 2005
Posts: 5

PostPosted: Tue Dec 06, 2005 3:40 pm    Post subject: Reply with quote

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. Smile
Thanks.
_________________
iran - mithras


Last edited by iranmehr on Tue Dec 06, 2005 8:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5608
Location: Toronto, Canada

PostPosted: Tue Dec 06, 2005 6:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
iranmehr
Smarty Rookie


Joined: 01 Nov 2005
Posts: 5

PostPosted: Tue Dec 06, 2005 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5608
Location: Toronto, Canada

PostPosted: Tue Dec 06, 2005 9:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
iranmehr
Smarty Rookie


Joined: 01 Nov 2005
Posts: 5

PostPosted: Wed Dec 07, 2005 4:57 am    Post subject: Reply with quote

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. Embarassed
_________________
iran - mithras
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5608
Location: Toronto, Canada

PostPosted: Wed Dec 07, 2005 6:08 am    Post subject: Reply with quote

Sorry, it seems my knowledge of MT's use of Smarty is too limited to be helpful here.

Good Luck!
Back to top
View user's profile Send private message
iranmehr
Smarty Rookie


Joined: 01 Nov 2005
Posts: 5

PostPosted: Wed Dec 07, 2005 7:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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