vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Help : customise block in the sidebare (https://vborg.vbsupport.ru/showthread.php?t=293516)

tounet 01-02-2013 02:02 PM

Help : customise block in the sidebare
 
I have a php file inspire the product "Rate My Photo (HorOrNot Clone)" and correctly displays the best picture of my database and uses a template but I am unable to make my block:

the php code

PHP Code:

<?php 

global $vbulletin;
// Include Globals
    
require_once('./global.php');

$bestphoto =$vbulletin->db->query_first("SELECT * FROM vb_ratemyphoto_photos WHERE approved=1 AND hidden=0 

AND rating>0 ORDER BY rating DESC, votes DESC LIMIT 1"
);
    
$besttitle htmlspecialchars_uni($bestphoto["title"]);
    
$bestphotoname $bestphoto["logo"];
    
$bestvotes $bestphoto["votes"];
    
$bestrating $bestphoto["rating"];
        
$templater vB_Template::create('block-photo');
        
$templater->register('besttitle'$besttitle);
    
$templater->register('bestphotoname'$bestphotoname);
        
$templater->register('bestvotes'$bestvotes);
    
$templater->register('bestrating'$bestrating);
    
$templater->register('bestuserid'$bestphoto[userid]);
    
$templater->register('bestusername'$bestphoto[username]);    
    
$templater->register('catid'$catid);
        
print_output($templater->render());
 
      
?>

the template :

HTML Code:

<li>
        <div class="block smaller">
                <div class="blocksubhead">
                Meilleur photo       
                </div>
                <div id="block_title" class="blockbody floatcontainer" {vb:raw content.style}>
                        <div class="blockrow">

        <img src="../forum/ratemyphoto/photo/thumbs/{vb:raw bestphotoname}"/>

                        </div>
                </div>
        </div>
        <div class="underblock"></div>
</li>
                </div>
        </div>
</div>       
<div class="underblock"></div>


kh99 01-02-2013 02:18 PM

Try this for the code:

Code:

global $vbulletin;

$bestphoto =$vbulletin->db->query_first("SELECT * FROM vb_ratemyphoto_photos WHERE approved=1 AND hidden=0

AND rating>0 ORDER BY rating DESC, votes DESC LIMIT 1");
    $besttitle = htmlspecialchars_uni($bestphoto["title"]);
    $bestphotoname = $bestphoto["logo"];
    $bestvotes = $bestphoto["votes"];
    $bestrating = $bestphoto["rating"];
        $templater = vB_Template::create('block-photo');
        $templater->register('besttitle', $besttitle);
    $templater->register('bestphotoname', $bestphotoname);
        $templater->register('bestvotes', $bestvotes);
    $templater->register('bestrating', $bestrating);
    $templater->register('bestuserid', $bestphoto[userid]);
    $templater->register('bestusername', $bestphoto[username]);   
    $templater->register('catid', $catid);
    return $templater->render();


tounet 01-02-2013 02:29 PM

Thank you but the block still appears empty

kh99 01-02-2013 03:52 PM

Have you created the template called "block-photo" (or does it exist already)?

tounet 01-02-2013 04:12 PM

Quote:

Originally Posted by kh99 (Post 2394247)
Have you created the template called "block-photo" (or does it exist already)?

I created it myself

her the link demo : her

kh99 01-02-2013 04:28 PM

Well, I can't really tell what's going on from that. One thing is that the template you posted doesn't have the tags matched - there's one more </div> than there is <div>.

Are you entering that template name in "Template to use"? If so, set "Template to Use" to block_html. Also, set "Cache Time (in minutes)" to 0 until you get it working, then set it to the number of minutes you want to cache.

Lynne 01-02-2013 04:40 PM

Replace this line:
PHP Code:

    return $templater->render(); 

With these:
PHP Code:

    $my_output $templater->render();
    return 
$my_output

And Kevin is correct in that your html template is improper html. I have no idea what it will do to the page if you leave it like that.

tounet 01-02-2013 04:52 PM

the new template :

HTML Code:

<div class="block smaller">
        <div class="blocksubhead">
                Meilleur photo
        </div>
        <div class="widget_content blockbody floatcontainer">
                <div class="blockrow" align="center">
                        <A HREF="ratemyphoto/photos/{vb:raw bestphotoname}"><img border="0" src="ratemyphoto/photos/thumbs/{vb:raw bestphotoname}"></A><br />
                       
                </div>
        </div>
</div>       
<div class="underblock"></div>

I have set "Template to Use" to block_html. and, set "Cache Time (in minutes)" to 0

https://vborg.vbsupport.ru/external/2013/01/4.gif

--------------- Added [DATE]1357149292[/DATE] at [TIME]1357149292[/TIME] ---------------

Quote:

Originally Posted by Lynne (Post 2394261)
Replace this line:
PHP Code:

    return $templater->render(); 

With these:
PHP Code:

    $my_output $templater->render();
    return 
$my_output

And Kevin is correct in that your html template is improper html. I have no idea what it will do to the page if you leave it like that.

PHP Code:

$my_output $templater->render();
    return 
$my_output

I tested with and it does not work

kh99 01-02-2013 05:00 PM

Quote:

Originally Posted by tounet (Post 2394266)
I have set "Template to Use" to block_html.

It says "block_photo" (unless you meant you changed it after making the screen grab). It *is* possible to use a custom template name there, but unless you want the "frame" part to look different than other blocks, I wouldn't do it that way.

Lynne 01-02-2013 05:03 PM

All your variables need to be returned as an array. Example:
PHP Code:

    $my_output = array('besttitle'$besttitle
    
'bestphotoname'$bestphotoname);
return 
$my_output 

And then you may use those variables in your template. I have a Users Online Block that I released (see my profile) and you can see how to use a custom template and return custom variables.

Christos Teriakis 01-02-2013 05:08 PM

I was out for holidays, so just seen it (in my site too). As I'm still out of my working area, the only that I can say for now is that you've an error in configuration. Is PHP block and not HTML.
For more, a bit later...

Chris

tounet 01-02-2013 06:56 PM

Quote:

Originally Posted by Lynne (Post 2394261)
Replace this line:
PHP Code:

    return $templater->render(); 

With these:
PHP Code:

    $my_output $templater->render();
    return 
$my_output

And Kevin is correct in that your html template is improper html. I have no idea what it will do to the page if you leave it like that.


Thank you for your reply but its not working

--------------- Added [DATE]1357156723[/DATE] at [TIME]1357156723[/TIME] ---------------

Quote:

Originally Posted by ChrisTERiS (Post 2394285)
I was out for holidays, so just seen it (in my site too). As I'm still out of my working area, the only that I can say for now is that you've an error in configuration. Is PHP block and not HTML.
For more, a bit later...

Chris

Thank you for your reply and I look forward

tounet 01-02-2013 08:55 PM

1 Attachment(s)
This post can be closed because I finally found the solution

PHP Code:

global $vbulletin;

$bestphoto =$vbulletin->db->query_first("SELECT * FROM vb_ratemyphoto_photos WHERE approved=1 AND hidden=0 

AND rating>0 ORDER BY rating DESC, votes DESC LIMIT 1"
);
    
$besttitle htmlspecialchars_uni($bestphoto["title"]);
    
$bestphotoname $bestphoto["logo"];
    
$bestvotes $bestphoto["votes"];
    
$bestrating $bestphoto["rating"];
        
$templater vB_Template::create('block_photo');
        
$templater->register('besttitle'$besttitle);
    
$templater->register('bestphotoname'$bestphotoname);
        
$templater->register('bestvotes'$bestvotes);
    
$templater->register('bestrating'$bestrating);
    
$templater->register('bestuserid'$bestphoto[userid]);
    
$templater->register('bestusername'$bestphoto[username]);    
    
$templater->register('catid'$catid);
    return 
$templater->render(); 

created template called "block_photo"
PHP Code:

Member: <a href="member.php?u={vb:raw bestuserid}&tab=ratemyphoto#ratemyphoto">{vb:raw bestusername}</a><br />
Nb rate: <b>{vb:raw bestvotes}</b><br />
Best rate: <b>{vb:raw bestrating}</b

setting:
Title : The best Photo
Description : The best photo enacted by Member ratemyphoto
Active : Yes
Content Type : php
Content : code php " Top "
Template to Use : block_html

Attachment 143157


All times are GMT. The time now is 10:29 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01249 seconds
  • Memory Usage 1,797KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_html_printable
  • (11)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (13)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete