lonnieezell / ocular-template-library Goto Github PK
View Code? Open in Web Editor NEWA template/layout library for CodeIgniter
Home Page: http://igniteyourcode.com/ocular
A template/layout library for CodeIgniter
Home Page: http://igniteyourcode.com/ocular
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('render'))
{
function render($data = array())
{
$CI =& get_instance();
$CI->template->set($data);
$CI->template->render();
}
}
// ------------------------------------------------------------------------
I found this useful and created for myself.
hope you like this idea.
it makes controller cleaner
I've modified Template.php to check if the $var_name is an array, and if so, walk it to set the key/vals on this->data.
This makes it easier to migrate an existing site that is using CI's standard $data way to Ocular.
Would be nice to have this implemented so future versions don't need to be patched.
Apologies if I'm missing something really simple here, but I need this functionality and I can't see how it is achieved.
This would be the equivalent of the standard CI $string = $this->load->view('myfile', '', true);
Can somebody point me in the right direction?
Thanks
When controllers are organized into sub-folders, the Template->render function should look in sub-folders for views too (mentioned as a future to-do on the old website).
I think it's as simple as adding the router->directory to line 236, like so:
$this->current_view = $this->ci->router->directory . $this->ci->router->class . '/' . $this->ci->router->method;
public function theme()
{
return $this->active_theme();
}
active_theme() is not a function, it is a variable
I'm working on troubleshooting this one, but wanted to log it.
Seems like if I have a theme set (this->active_theme) and it's missing a view file, it will never get to loading the missing file from the this->default_theme folder.
Upon cursory review, it seems the Template.php library is relying on $content being populated from CI->load->view to determine how to proceed. This is a catch-22 in that if CI-load->view can not find the passed view name (because say we want to revert to default), CI will throw a 404, never allowing Ocular to revert to this->default_theme's view.
I'm testing this in 2.0, FWIW.
The $bypass always set to FALSE, the effect is the view rendered first before the layout (the yield method $this->template->yield not running)
then i hardcoded the function (yield) i set the $bypass to TRUE, then is running.
public function yield($bypass=FALSE) {
$this->_mark('Template_Yield_start');
// If we've cached the layout, we don't return anything except the
// yield function itself.
if ($bypass === TRUE) { // I CHANGED TO TRUE
return '{yield}';
} else {
$this->_render_view($this->current_view, $this->cache_view);
}
$this->_mark('Template_Yield_end');
}
For some reason, I have to add "layouts/" to my config/template.php file:
$config['OCU_ajax_layout'] = 'layouts/ajax';
Without it, I keep getting 500 server errors.
May have something to do with closed Issue #2 (http://github.com/lonnieezell/Ocular-Template-Library/issues/closed/#issue/2)
I installed the latest version and did a very basic test. I found that when I viewed the source code, the view content was showing up above the layout content. I looked through the code and here's what I found:
In the Welcome controller index method, I call the template render method:
$this->template->render();
In theTemplate libraray render() method, {yield} string is replaced with the return value of the yield function (with bypass set to true):
$output = str_replace('{yield}', $this->yield(true), $output);
However, the yield function doesn't seem to return a value when bypass is set to true (line 321):
$this->_render_view($this->current_view, $this->cache_view);
... and the called _render_view() method doesn't return view content either, but instead echos the content directly (line 727):
echo $content;
return true;
The end result of this seems to be that calling $this->template->render() in my controller echoes the view content, then the layout content. Am I missing something, or is this a bug?
Benchmarking pseudo variables not showing anymore... Using v2.0.3 was ok
500 Internal Server Error when Template library wants to load config file on line #173 of ~/application/libraries/Template.php
$this->ci->config->load('template');
When I remove this line and autoload the config file then it works fine.
Would you mind providing some info to make Ocular work with HMVC plz?
Hopefully the title here isn't too confusing, and this is more a request than an issue.
Right now, Block's can be rendered using data provided by the Controller, but not by the parent View. For instance, I have the following:
<ol>
<?php foreach ($entries as $entry) { ?>
<li>
<h3>$<?= $entry->amount; ?></h3>
<h2><?= $entry->description; ?></h2>
<p><?= $entry->budget; ?></p>
</li>
<?php }; ?>
</ol>
I was hoping to be able to extract the HTML for a single entry, and use it as a Block. I was hoping that I could updated my View to be:
<ol>
<?php foreach ($entries as $entry) { ?>
<?= $this->template->block('single_entry', 'entry/single'); ?>
<?php }; ?>
</ol>
With my single.php view (partial?) containing:
<li>
<h3>$<?= $entry->amount; ?></h3>
<h2><?= $entry->description; ?></h2>
<p><?= $entry->budget; ?></p>
</li>
However, it appears that the $entry variable isn't passed to the block. Not sure if I'm missing something.
It would be really great to have support for something similar to rails collections, using the format:
<ol>
<?= $this->template->block('single_entry', 'entry/single', $entries as $entry); ?>
</ol>
Anyways. Great work! I'm loving Ocular!
Hello,
I'm trying to put in my aplication.php file to load a menu.php file. but the browser stop in that place.
i don't find any documentation about the function in the wiki.
i was seeing the function and the code and i think the error is in $ci->template->render_view($view);
Tanks,
Domingos
I may be missing a config, but the Current View is always displayed at the top of the page:
Lines 233 through 239 of application/libraries/Template.php:
// Grab our current view name, based on controller/method
// which routes to views/controller/method.
if (empty($this->current_view))
{
$this->current_view = $this->ci->router->directory . $this->ci->router->class . '/' . $this->ci->router->method;
echo 'Current View = '. $this->current_view;
}
I couldn't find any way to turn this off, other than commenting out the echo statement.
Because it uses session library from CI Core, I had to follow two steps to get messages working correctly:
$autoload['libraries'] = array(..., 'session');
Is there a way not to use sessions? I didn't figure out why.
Thanks for the best CI template library!
Just as the title suggests, when using the set_message method to set flashdata, the message displayed once on the resulting render and again on the subsequent page load. I looked at the method in the template library to find a typo that fixed the problem once corrected. Here is the typo:
In the template library, at the end of the message method, find
$this->ci->session->flashdata('message', '');
and replace it with
$this->ci->session->set_flashdata('message', '');
The following changes need to be made:
in views/layout/ajax.php:
ocular->yield(); ?>to
template->yield(); ?>and in Template.php, line 234:
$layout = $this->ci->config->item('OCU_layout_folder') . $this->ci->config->item('OCU_ajax_layout');
i have this this action in Welcome controller:
function index() {
$this->template->render();
}
i create 1 view ('view/welcome/index.php') and the content is
Page rendered in {elapsed_time} seconds using {memory_usage}.
Getting "Parse error: syntax error, unexpected 'yield' (T_YIELD), expecting identifier (T_STRING) in .../application/libraries/Template.php on line 314", when using PHP 5.5+, where there is a new keyword "yield", which conflicts with the method name used in the library.
On line 238 of the library file, is that an oops? I'm new with Codeigniter, took a bit to figure that out, it displayed at the top of every page
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.