mirror of
https://github.com/bcit-ci/CodeIgniter.git
synced 2025-02-20 11:13:29 +08:00
...
parent
67c2d111f5
commit
21cab15f4a
98
render.md
Executable file
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, it’ll 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);
|
||||
|
||||
That’ll produce the equivalent of <span class="bigbox"><span class="littlebox"><h1>Your content here...</h1></span></span>
|
||||
|
||||
If your ‘wrap’ data doesn’t have a middle, it’ll prefix or post-fix the tags as you might expect. I was aiming for the jQuery “wrap” function, if you’re familiar with it.
|
||||
|
||||
[code]
|
||||
<?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) == '</')
|
||||
{
|
||||
$this->view($view, $vars, $return);
|
||||
$this->bypass_view($vars['wrap']);
|
||||
} elseif (strstr($vars['wrap'],'></') == FALSE)
|
||||
{
|
||||
$this->bypass_view($vars['wrap']);
|
||||
$this->view($view, $vars, $return);
|
||||
} else
|
||||
{
|
||||
$bookends = explode('></',$vars['wrap'],2);
|
||||
$this->bypass_view($bookends[0].'>');
|
||||
$this->view($view, $vars, $return);
|
||||
$this->bypass_view('</'.$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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
[/code]
|
Loading…
x
Reference in New Issue
Block a user