Rouven
> --
> You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
> To post to this group, send an email to joomla-...@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>
I have made a plus / minus counter for Kunena per post
Well, you can, but it's ugly. You can make a system plugin that checks
for your specific url, does something, spits out the json, and dies.
However, it's much CLEANER to do this via a component.
The summary:
Add &format=json&tmpl=raw in your query string
create the files view.json.php and default_json.php to do your special
processing
Everything works. Grab a beer.
-----
The long winded, ask me the time and I tell you how to build a clock,
commentary:
I assume you already now how to make a component which returns html. Ie
using the files
componentname/viewname/view.html.php
componentname/viewname/tmpl/default.tpl
Now the view.html.php is actually determined depending on what format
the browser says it wants the data in. If you add &format=ejs then the
file used would be view.ejs.php, if you add &format=json then the file
used is view.json.php. One exception, if you add &format=html5 because
you want a specific cool html5 format and to allow for fallback to
view.html.php for older browsers - your out of luck. If the first 4
charectors of the viewname are html, view.html.php is always used. So
you would have to use &format=5html to do it.
So now you have a view that can respond to ajax requests and will return
json data. But what about the template? No problem, format is used
there as well.
default.php
default_html.php
default_json.php
If default_html.php exists, it is used instead of default.php. Same
deal with default_json.php
So far so good. So now can create a component which returns json data.
But your still stuck with all the other modules and stuff. So how do
you get past that?
2 ways: add either tmpl=component or tmpl=raw to your query string.
tmpl=raw is safest.
tmpl=raw means no template will be loaded. Just the results of the
component plus any plugins which are called will be sent back, in
whatever way they are formatted.
tmpl=component instead will use the component.php file[if one exists] in
the template directory instead of the index.php file. Since most
templates do NOT have a component.php file the effect would be the
same...but if yours does...
If the component is cleanly laid out and all the display is done in the
template file[default.tpl] then you can add an override to your
template. IE
templatename/html/com_kuenena/<viewfolder>/default.json.tpl
As long as it is using the native API's and not hardcoding the html
layout parameter, Joomla! should automatically use the override.
You can also create your own component:
components/com_kajax
And use a plugin to 'hijack' any requests for the kunena component which
have are ajax requests[aka set the format=json parameter].
Lastly, provided that the COMPONENT utilizes the Plugin system, if there
is a suitable view event you can call
$view->addTemplatePath(JPATH_BASE.'/libraries/mydisplayhacks/com_kunena/')
or some such variation and you can place your template overrides at the
head of the list. I think for the content component onContentPrepare
would be the appropriate one?
There probably are a couple more entry points into adding templates to
the view's Template Path depending on where it gets that array from[the
document?]
The more I dig, the more I find a lot of my "I wish Joomla! had a way"
wishes are in there already. It just takes digging through the code
line by line.
I made a slight mistake, if you use $format=json as your keyword, you
should not have to specify &tmpl=...
In libraries/joomla/document there are SEVEN formats already defined for
you.
error, feed, html, json, opensearch, raw, and xml
If you use the json format, Joomla should use the JDocumentJSON class
instead of JDocumentHTML - and JDocumentJSON completely bypasses the
template and just returns the results from the component.
As for documented somewhere, feel free to take what I've written and
post it to Joomla!'s wiki a bit more coherently.... I'm switching
mental gears for the day.
> You can also create your own component:
> components/com_kajax
> And use a plugin to 'hijack' any requests for the kunena component which
> have are ajax requests[aka set the format=json parameter].
Sorry, this would indeed work, but again it is overkill to add such
simple functionality when you can do it with a system plugin and two
methods.