[dokuwiki] Re: javascript with php global variables
- From: Michiel Kamermans <pomax@xxxxxxxxxxxxxxxxxxxx>
- To: dokuwiki@xxxxxxxxxxxxx
- Date: Tue, 17 Nov 2009 22:44:34 -0800
James,
How do I get my ajax javascript to use the php global variables? Eg. I
want my plugin javascript to read the $INFO, $AUTH etc of the page
everytime when I click a button.
The real question is "why?". If there are values in these session
variables that you want, then perhaps you want to explicitly extract
these in your plugin and then pass them to your javascript, for instance
via dokuwiki's addInitEvent() javascript function:
<?php
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_yourplugin extends DokuWiki_Action_Plugin {
function register(&$controller)
{
// hook into XHTML
$controller->register_hook('RENDERER_CONTENT_POSTPROCESS',
'AFTER', $this, '_varpass');
}
function _varpass(&$event, $param)
{
// make sure this is the xhtml output
$data = &$event->data[1];
$datatype = &$event->data[0];
if ($datatype != 'xhtml') { return; }
// grab relevant vars
$statevar = $INFO['...'];
...
// add a javascript event to dokuwiki's event list (handled
before a DOM exists)
$data[] = "addInitEvent(function(){ var statevar = $statevar;
...;});";
}
}
?>
But the real question is of course still "why do you need session
variables passed to javascript". The session variables exist on the
server, for the purpose of session administration and content
generation, and javascript should be agnostic towards what these session
variables say - instead, you should generate your page in such a way
that the right javascript is loaded because your plugin generates
different content based on the content of the different session variables.
- Mike "Pomax" Kamermans
nihongoresources.com
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist
Other related posts: