1 (edited by 2012-02-21 18:48:26)

Topic: Insert code php in template (.tpl)

Hi!, I need your help.

I have to insert this code in a .tpl :

<?php rating_form("{news-id}"); ?>

As the templates are already php code , I can not do this:

<?PHP
$template_active = <<<HTML
<?php rating_form("{news-id}"); ?>
HTML;
?>


I need to insert between the tags <<<HTML HTML; to operate {news-id}

Thanks for any inconvenience.

Re: Insert code php in template (.tpl)

Dear User!

Unfortunately, PHP code is not executed in the patterns. If you want ID news to be displayed, please try using {news-id}.

Best regards,
CN Support team

Re: Insert code php in template (.tpl)

Viewing the following code ....

<?PHP
$template_active = <<<HTML
<!--Here code for news-->
HTML;
?>
 <?php rating_form("{news-id}"); ?>

All works, except that the variable {news-id} does not take its value to be out of the labels <<<HTML--- HTML;
Is there any way to do this?

Note: Sorry, my English may not be very good

4 (edited by 2012-02-22 13:26:02)

Re: Insert code php in template (.tpl)

First off, your English is great!

Adding PHP to the templates isn't possible and shouldn't be done as it poses a big security risk you don't want to take. Just adding the function rating_form() to the .tpl file isn't ideal. The rating form will display as soon as CuteNews loads the .tpl file, so that will be above the actual news article. Moreover, the rating form won't be displayed for further articles in active news, and I'm sure you'd want to have all news article having the rating form.

What I propose is that you add the code to /inc/shows.inc.php, provided that CuteNews always knows where to find rating_form(), since that's not a standard function. I'm not familiar with the hack, so I don't know which file you had to edit for the additional code.

Basically, you want the rating form to display after every news article? This can be done in /inc/shows.inc.php:

Find twice:

$output = str_replace("{full-story}", $news_arr[4], $output);


Replace both times with

$output = str_replace("{full-story}", $news_arr[4].rating_form($news_arr[0]), $output);

The line is in /inc/shows.inc.php at lines 366 and 695 in an unmodified CuteNews 1.4.6. They're the only two lines that have {full-story} in them - easy to find!

$news_arr[0] is the news ID. I don't think that replacing {news-id} with $news_arr[0] in the .tpl file will work.
Please also note that adding PHP manually to the .tpl files may cause errors in the Templates module of the administration area, and it will be lost if someone resaves the template.

Re: Insert code php in template (.tpl)

Thank you very much! It has helped me a lot of your answer.

Posts: 6

Pages 1

You must login or register to post a reply

CutePHP Forums → Problem Solving / Help & Support → Insert code php in template (.tpl)



The pun_antispam official extension is installed. Copyright © 2003–2009 PunBB.