...

World Wide Web Server 2012-07-04 16:04:47 -07:00
parent 67c2d111f5
commit 21cab15f4a

98
render.md Executable file

@ -0,0 +1,98 @@
Do you love the simplicity of the CI view loader but just can't stomach loading a whole file just to add a couple of span tags and a whole other file just to close them?
I think you might find a happy medium with this library.
Essentially, itll let you call a view with a wrapper command and some data like so:
$data[wrap] = <span class="bigbox><span class="littlebox></span></span>;
$this->render->wrap(content,$data);
Thatll produce the equivalent of <span class="bigbox"><span class="littlebox"><h1>Your content here...</h1></span></span>
If your wrap data doesnt have a middle, itll prefix or post-fix the tags as you might expect. I was aiming for the jQuery “wrap” function, if youre familiar with it.
[code]
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter Render Class
*
* @package CodeIgniter
* @subpackage Library
* @category View
* @author Bradford Mar
* @version 0.1
* @link http://codeigniter.com/wiki/render/
* @license http://creativecommons.org/licenses/by-sa/3.0/
*/
class Render
{
/**
* wrap
*
* Quickly wrap tags around your view.
*/
function wrap($view, $vars = array(), $return = FALSE)
{
if (isset($vars['wrap']))
{
if (substr($vars['wrap'],0,5) == '&lt;/')
{
$this->view($view, $vars, $return);
$this->bypass_view($vars['wrap']);
} elseif (strstr($vars['wrap'],'&gt;&lt;/') == FALSE)
{
$this->bypass_view($vars['wrap']);
$this->view($view, $vars, $return);
} else
{
$bookends = explode('&gt;&lt;/',$vars['wrap'],2);
$this->bypass_view($bookends[0].'&gt;');
$this->view($view, $vars, $return);
$this->bypass_view('&lt;/'.$bookends[1]);
}
} else
{
log_message('debug', "No wrapping for ".$view);
$this->view($view, $vars, $return);
}
}
/**
* bypass_view
*
* All the benefits of a view sans the file.
*/
function bypass_view($rushtml)
{
ob_start();
echo html_entity_decode($rushtml);
// PHP 4 requires that we use a global
global $OUT;
$OUT->append_output(ob_get_contents());
@ob_end_clean();
}
/**
* send
*
* Call this after loading all of your views to run XSLT before sending.
*/
function send($xslview)
{
$xml = new DOMDocument();
$xml->loadXML($this->output->get_output());
$xsl = new DOMDocument();
$xsl->loadXML($this->load->view('base',null,true));
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
$html = $xslt->transformToXML($xml);
$this->output->set_output($html);
}
}
?&gt;
[/code]