PDA

View Full Version : Help : customise block in the sidebare


tounet
01-02-2013, 02:02 PM
I have a php file inspire the product "Rate My Photo (HorOrNot Clone) (https://vborg.vbsupport.ru/showthread.php?t=289735)" 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

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 :

<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:

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
Have you created the template called "block-photo" (or does it exist already)?

I created it myself

her the link demo : her (http://www.algcanari.com/forum/ratemyphotoblock.php)

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:
return $templater->render();

With these:
$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 :

<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 (http://www.servimg.com/image_preview.php?i=428&u=10094503)

--------------- Added 1357149292 at 1357149292 ---------------

Replace this line:
return $templater->render();

With these:
$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.

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

I tested with and it does not work

kh99
01-02-2013, 05:00 PM
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:
$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
Replace this line:
return $templater->render();

With these:
$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 1357156723 at 1357156723 ---------------

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
This post can be closed because I finally found the solution

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"
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

143157