Show votes in article header along with author, date etc

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
bdam
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jan 23, 2017 8:36 am

Show votes in article header along with author, date etc

Post by bdam » Sun Nov 12, 2017 10:08 pm

I know if I override content\info_block\block.php I can control a bunch of fields, and to make them appear I do something along the lines of echo JLayoutHelper::render('joomla.content.info_block.author', $displayData);

What I'm trying to do is get the article votes to appear here. it's actually a 3rd party one I'm using which just shows stars, but it's a direct replacement for the default one. I understand they are both implemented as plugins and am guessing that's why I'm having a hard time finding the actual line to invoke them. So if anyone knows what I'd need to add into this block.php to make them appear I'd really appreciate it, thanks.

User avatar
effrit
Joomla! Guru
Joomla! Guru
Posts: 846
Joined: Sun Nov 12, 2017 2:21 pm
Location: middle of Russia
Contact:

Re: Show votes in article header along with author, date etc

Post by effrit » Mon Nov 13, 2017 4:14 am

standard vote plugin add its content before or after main content via onContentBeforeDisplay, onContentAfterDisplay events.

Code: Select all

\plugins\content\vote\vote.php
this string do the trick.

Code: Select all

$html .= ob_get_clean();
so to customize, you must store somehow ob_get_clean() data or make regular replacement it your template

for example
replace original string i mentioned to

Code: Select all

$params->votte = ob_get_clean();
then in article template you can do

Code: Select all

echo $params->votte;

bdam
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jan 23, 2017 8:36 am

Re: Show votes in article header along with author, date etc

Post by bdam » Tue Nov 14, 2017 8:24 pm

I tried using ob_get_clean(); in block.php but it totally screwed the whole site up! I must admit I don't really understand how this is supposed to fit in.

User avatar
effrit
Joomla! Guru
Joomla! Guru
Posts: 846
Joined: Sun Nov 12, 2017 2:21 pm
Location: middle of Russia
Contact:

Re: Show votes in article header along with author, date etc

Post by effrit » Tue Nov 14, 2017 9:03 pm

logic is simple:
in
\plugins\content\vote\vote.php
you store code in $params->votte
read how ob_get_clean() works in php

and in article template you just draw it by
echo $params->votte;

bdam
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jan 23, 2017 8:36 am

Re: Show votes in article header along with author, date etc

Post by bdam » Wed Nov 15, 2017 1:00 pm

OK thank you I have made some progress. I have seen the line which constructs the html in the source:

$html .= $this->plgContentExtraVoteStars( $this->article_id, $rating_sum, $rating_count, $article->xid, $ip );

So how do I add this instead to $params? I mean, where you just said "you store code in $params->votte" I can't get the syntax right to do that - what is the line please?

Btw I am working with the 3rd party ExtraVote now directly.

User avatar
effrit
Joomla! Guru
Joomla! Guru
Posts: 846
Joined: Sun Nov 12, 2017 2:21 pm
Location: middle of Russia
Contact:

Re: Show votes in article header along with author, date etc

Post by effrit » Wed Nov 15, 2017 1:02 pm

Code: Select all

$params->votte = $this->plgContentExtraVoteStars( $this->article_id, $rating_sum, $rating_count, $article->xid, $ip );

bdam
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jan 23, 2017 8:36 am

Re: Show votes in article header along with author, date etc

Post by bdam » Wed Nov 15, 2017 2:03 pm

Hey thanks - I am so close now!
Remember I am working in bock.php.
In that file, if I do

echo $params->votte;

I get crash with undefined variable prams

But I see elsewhere in that file many refs to for example

$displayData['params']->get('show_parent_category')

So I then try

echo $displayData['params']->get('votte')

But it comes out blank however, if I do

var_dump($displayData['params']);

I see the stars - here's the end of the dump, you'll see "1 1 1 1" where I see star icons

["robots"]=> NULL ["access-view"]=> bool(true) } ["initialized":protected]=> bool(true) ["separator"]=> string(1) "." ["votte"]=> string(2106) "
51 1 1 1 1 1 1 1 1 1
" }

It looks like it has passed the html over but I just now need to know how to get it & I'm done!

User avatar
effrit
Joomla! Guru
Joomla! Guru
Posts: 846
Joined: Sun Nov 12, 2017 2:21 pm
Location: middle of Russia
Contact:

Re: Show votes in article header along with author, date etc

Post by effrit » Wed Nov 15, 2017 2:30 pm

i an not programmer so its hard for me too )
maybe

Code: Select all

$displayData['params']->votte;

bdam
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jan 23, 2017 8:36 am

Re: Show votes in article header along with author, date etc

Post by bdam » Wed Nov 15, 2017 2:49 pm

Yay! It works. Thank you x 1 million. I learned a lot there. !!!


Locked

Return to “Joomla! 3.x Coding”