GithubHelp home page GithubHelp logo

vheissu / ci-smarty Goto Github PK

View Code? Open in Web Editor NEW
179.0 28.0 43.0 991 KB

Smarty templating engine integration for Codeigniter 3.0+ with inbuilt theming and asset management.

Home Page: http://ilikekillnerds.com

PHP 97.85% Smarty 2.15%

ci-smarty's Introduction

CI Smarty

Integrate Smarty into your Codeigniter applications.

Development Notice

I no longer maintain this repository. Please note that many aspects of this repository probably need to be updated.

How to use it?

Drop the contents of the download zip into your application directory, then edit your autoload.php file in the config folder, and add 'parser' to your list of autoloaded libraries. Instead of using $this->load->view() you now use $this->parser->parse() instead. That's it.

Supported versions of Codeigniter

CI Smarty has been tested and working on the latest version of Codeigniter (3.0). It will most likely work with older 2.x versions as well, but these aren't supported anymore and you should be using 3.0.

Theming support

CI Smarty comes with complimentary functionality to add theming support in your Codeigniter applications. Simply create a themes directory in the root folder of your app and then inside of that folders of themes. If you're not using themes, then don't add anything and CI Smarty will work fine without them. It's a good idea if you're building a web app to have a default theme in application/themes/themename and then allow themes in a different directory to override your default theme files.

Asset management

When dealing with themes you want to include static content like images and stylesheets. By calling; {css('file.css')}, {js('file.js')}, {img('file.jpg')}, etc in your themes files will automatically be embedded. It is assumed your files are in the directories; themename/css, themename/js and themename/images. To get a web friendly URL to your themes directory simply use: {theme_url()} which also supports adding file and folders.

HMVC/Modules

This library should work with various HMVC solutions (including Modular Extensions). However, no guarantee is given that CI Smarty will work with other third party libraries.

Issues

If you run into any issues, especially the Codeigniter blank screen of death issue there is a simple fix. CI Smarty creates new cache folders in your application/cache directory and needs them to be writable. Issues I've encountered are generally the folders aren't owned by correct user and group doing a: chown www-data:www-data (at least on Ubuntu) on your caching folder will fix the issue.

ci-smarty's People

Contributors

cjonstrup avatar fadillzzz avatar icehawg avatar joearcher avatar nakp avatar octaaugusto avatar vheissu avatar zofrex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ci-smarty's Issues

Error reporting

Error reporting doesn't appear to work properly. In the config I have set error reporting to:

$config['template_error_reporting'] = "E_ALL ^ E_NOTICE";

so that any notices don't show up. However in the CI log files it seem to interpret it as an error? E.g:

ERROR - 2011-12-02 21:00:54 --> Severity: Notice --> Undefined index: foo \cache\smarty\compiled\b45265bb89040a86b3bc4d30ea7ca5c612acb525.file.bar.tpl.php 55

I can't work out how to stop these appearing, any ideas?

I'd rather not have to go through every variable and do {if isset($foo)}

Thanks

Need documentation

Hello,
at first great work!
But... could you write a full documentation for it ?
Reverse-Engineering of some methods is not really funny, when anyone should use your library.

Example:
Possible View-Paths:

// Store a whole heap of template locations
        $this->_template_locations = array(
            config_item('smarty.theme_path') . $this->_theme_name . '/views/modules/' . $this->_module .'/layouts/',
            config_item('smarty.theme_path') . $this->_theme_name . '/views/modules/' . $this->_module .'/',
            config_item('smarty.theme_path') . $this->_theme_name . '/views/layouts/',
            config_item('smarty.theme_path') . $this->_theme_name . '/views/',
            APPPATH . 'modules/' . $this->_module . '/views/layouts/',
            APPPATH . 'modules/' . $this->_module . '/views/',
            APPPATH . 'views/layouts/',
            APPPATH . 'views/'
        );

        // Will add paths into Smarty for "smarter" inheritance and inclusion
        $this->_add_paths();

Second thing is, i can only give you a good reputation for your work. It also seems that the library supports 100% all smarty functions, like blocks, captures and more.

Also is a usage with HMVC and Doctrine as ORM possible.

Great work, but documentation is mhh... worse...

Smarty Inheritance does not play nicely with HMVC

I am using Code Igniter, The HMVC library, and Smarty with this library.

Smarty is working fine by default, however if I try to use smarty's inheritance feature ( {extends file="master.tpl"}) then we run into an issue.

The extends feature does not look in the module views folder for the extended file (in the above's case master.tpl), instead it only looks in the application/views/ folder and throws an error if it cannot find it.

I could add APPPATH."modules/smartytest/views" to the $config['template_directory'] array in the smarty config file. but that throws an error for each item in the array it checks first for the file. filemtime(): stat failed for application/views/master.tpl

and that has the added issue of, if I have three modules all the the array and the modules all have a master.tpl then no matter what module I call the extend from it will load the first one found.

So, is there a way to get smarty's extend function to behave nicely with the HMVC modules?

Parser does not work with every $config['base_url'] format.

Hi, I've just noticed a strange thing. When base_url in config file is set to:
$config['base_url'] = 'localhost';

Parser works fine for me but when I renamed this value to:
$config['base_url'] = 'http://localhost'/; //as it should be

all I got was a blank page (funny thing, page source was ok).
This is my sample template file:

{$template_type = 'frontend'}
{$articleTitle|default:'no title'}
<html>
<head>
    <title>{$title}</title>
    {$css}
    {$js}
</head>
<body>
    {$body}<br>
    {lang line="test"}<br>
    {$themeurl}<br>
    <img src="{$themeurl}images/shared/content_repeat.jpg">
</body>
</html>

You can see some test variables.

Lets look at
{$articleTitle|default:'no title'}

When cache dir is empty and I load the page in browser 'no title' appears for a short moment then it disappears (but page source is still ok)
Also I can copy page content with Ctrl+A, Ctrl+C like every normal page.

In desperation I set chmod 777 to whole htdocs/ folder but still nothing.

error when i try to initialize annother controller

hay i have try your library is very helpfull thanks to you for create this library.

i have problem when i try this code

class Smartytest extends CI_Controller {

public function __construct()
{
    parent::__construct();

    // Ideally you would autoload the parser
    $this->load->library('parser');

}


public function index(){
    **require APPPATH.'controllers/Welcome.php';**
    // $this->load->library('mods_menu');
    **$mod = new Welcome();**
    $themes_name = 'eshopper';
    $data['themes'] = $themes_name."/index.tpl";
    $this->parser->parse('coba_menu.tpl',$data,false,false,$themes_name);

}

}

when i try this code it's showing error like this

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$load

Filename: libraries/MY_Parser.php

Line Number: 32

Backtrace:

File: D:\xampp\htdocs\ecomerce-modular-front\application\third_party\Smarty\Smarty.class.php
Line: 1547
Function: call_user_func

File: D:\xampp\htdocs\ecomerce-modular-front\application\libraries\MY_Parser.php
Line: 32
Function: mutingErrorHandler

File: D:\xampp\htdocs\ecomerce-modular-front\application\controllers\Smartytest.php
Line: 40
Function: __construct

File: D:\xampp\htdocs\ecomerce-modular-front\index.php
Line: 315
Function: require_once

i don't know why must do. i hope you help me on this issue thanks

Code running past parse method

I understood that when the $this->parser->parse() method was called this would output the display. I thought this was the case in all apps which I'd written to date. However, it turns out in a recent development project that I have clauses governing whether a template should be shown, or whether execution should proceed, and the line after the parse is being reached - see below.

$this->parser->parse('website/templates/test.tpl', $this->view_data);
echo "continuing here...";

The only way I can find round this is to add a "return" method after the parse. This works ok, but I'm just checking if this is the right way, or if I'm missing something?

integrating with other views

Hi
It looks like i have to include $this->load->library('parser'); in every controller i write?. Suppose i created a controller forum.php, now when i navigate to its view -
htp://localhost/codeigniter/forum/forum_view , forum_view content will be loaded.How i do so that that view will be loaded in a content section of smarty template? as far as i get i have to start -
class Forum extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('parser');
}
}
Then ? documentation is not found properly, so that will be a lot's of problem for starters.

Use Ci-Smarty to extend from the controller

I was looking on the smarty forum and found how to extend from the controller first before loading the view http://www.smarty.net/forums/viewtopic.php?p=71402&sid=a001c28775ec07f85bce6d3c91b90848

if(!empty($_REQUEST['lightbox']) {
$smarty->display("extends:general/{$config->template->base1}|detail.tpl");
} else {
$smarty->display("extends:general/{$config->template->base2}|detail.tpl");
}

Is it possible to do this with your Ci-Smarty

$this->parser->parse('login/login.tpl', $this->view_data);
Im looking to choose which file to extend first then load the login.tpl

Smarty Variables

Hi,

I have included your library witch works great! I am working at my job with smarty for some time now but i noticed one thing.

When i use a variable in the tpl file but i won't declare it in the controller i won't get any error. I set the error reporting in the smarty config to -1 that didn't work then i set it to E_ALL that also didn't work.

Do you have any idea how to get the errors to show up?

Unable to load the requested class: Ci_smarty

Hi !
I got this error message:
(Unable to load the requested class: Ci_smarty)
When i upload my project to server.

If I test in localhost this is work fine !!
Any idea?
What is the problem?

I use CodeIgniter-3.0.3

I have problem about cache page

My template is detail.tpl
I used as $this->parser->parse("article/detail.tpl",$data);
Data have "title 1" and url example.com/article/1
When i change url to example.com/article/2 (Data have "title 2")
=> Data don't change to "title 2", Data still show "title 1".
Please help me. Thanks

Template not found during HMVC Modules::run

It seems that if you call Modules::run('differentModule/controller') in a Smarty template, then any templates loaded in that module will not be found. This is because the current module is no longer $this->_module. I don't know if this is a bug though or if I'm doing something wrong, but I thought I'd report it along with my solution.

Modifying _find_view() around line 310 in MY_Parser as follows seems to solve the changing module problem. This will detect the module change and inject the relevant paths just for this template call.

        // We have no path by default
        $path = NULL;
        $locations = $this->_template_locations;

        $current_module = $this->current_module();

        // If the current module differs from the stored one, we have a Modules::run() call.
        // Add the new module's path to this search.
        if ($current_module !== $this->_module)
        {
            $new_locations = array(
                    config_item('theme_path') . $this->_theme_name . '/views/modules/' . $current_module .'/layouts/',
                    config_item('theme_path') . $this->_theme_name . '/views/modules/' . $current_module .'/',
                    APPPATH . 'modules/' . $current_module . '/views/layouts/',
                    APPPATH . 'modules/' . $current_module . '/views/'
            );

            // Add module paths first so they take precedence
            foreach($new_locations as $new_location)
            {
                array_unshift($locations, $new_location);
            }
        }

        // Iterate over our saved locations and find the file
        foreach($locations AS $location)

/libraries/Smarty.php

I have CI 3 and had a problem after i copied all of your files to codeigniter application folder.
Something worked but config file was ignored.

When i used $this->CI->load->library('smarty'); in MY_Parser.php was included original Smarty class instead of CI_Smarty in /libraries/Smarty.php. I copied it into system/libraries and it works well.

Smarty.php has incorrect code to add helpers from CI

On line 26 of Smarty.php in libraries directory, your code is incorrect as you aren't suppose to be looking for files to add to the plugins_dir for smarty but a actual folder. Change line 26 to
$helpers = glob(APPPATH . 'helpers/', GLOB_ONLYDIR | GLOB_MARK);
or otherwise it only works if the user should create a dir inside helpers and store all there smarty plugins in that dir. Please add some documentation around this as its vague atm.

using with HMVC

Hi, Thanks for creating the library !
How can I use the plugin with hmvc ?

I want to use the views in the modules..

Using "fetch" with HMVC

I have one module fetching the view, like:

class News extends MX_Controller {

public function index() {
    $this->parser->parse('news.tpl');
}

public function html() {
    return $this->parser->fetch('news.tpl');
}

}

But when I call it from a different module controller, it says news.tpl cannot be found !!!

class Page_Main extends MX_Controller {

public function index() {

    $data['title'] = 'Main Page';                
    $data['main'] = Modules::run('news/html');

    $this->parser->parse('page_main.tpl', $data);
}

}

filemtime stat failed

Severity: Warning --> filemtime(): stat failed for application/views/application/views/questions/view.tpl /var/www/application/third_party/Smarty/sysplugins/smarty_resource.php 352

The CI logs are being filled up with the above errors but the parser is working fine. Suggest how to suppress the errors

{PHP} tags

how would i go about using them?

{PHP} tags it gives Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "application\views\news\profile.php" on line 1 "{php}" unknown tag "php" <-- thrown in G:\wamp\www\frame\application\third_party\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 1 when i use it.

how would i go about allowing it?

not working with CodeIgniter-2.1-internationalization-i18n

Hi, I'm using your Ci-Smarty templating engine, but i can't get it to work with the https://github.com/EllisLab/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n, for some reason it loads the first page (the function index()) just fine, but it wont load the other pages, it simply shows the 404 page.

Using the url 'http://localhost/tvicarus/en/' it loads the index page but if i select other page like 'http://localhost/tvicarus/en/guide' it justs show the 404 page.

But if i change the index page to other one it loads.
For example:

 public function index() {
    $this->news();
 } #index

it loads the news as first page, if I change to other page, like

 public function index() {
   $this->guide();
 } #index

it loads the guide, as first page, without any problem.

Can you help me and try to make it work?

Thank you.

Class 'MY_Loader' not found

I'm getting this error while accessing 'smartytest'

Fatal error: Class 'MY_Loader' not found in /Users/saneef/Workspace/gungroo/src/app/application/libraries/MY_Parser.php on line 16

Not working at all

Hi, I've installed and its supposed to work out of the box right? well I've tried with the test controller and loads nothing but a blank page :/ not even debug info about what could be wrong, It seems there's an issue with MY_Parser class as it's not loading even normal views or normal templates, I remove MY_Parser and everthing works fine.. I'll check the code :)

uncaught exception:Missing template name

I merely follow the steps you explained in "how to use" section, I unzip the archive, copy it's contents to my application folder, then I edit autoload.php, finally I change this->load->view to this->parser->parse just as I should. But this is what I get:
adsiz
Please help me fix this,thanks.

PHP 7.2

File -> smarty_internal_compilebase.php
$kv = each($mixed);
This function dont exist on php 7.2

non-standard ci installation

I have a CI installation with a folder structure a little bit different from the standard

app
|-> system
|-> application
www
|-> index.php

In this scenario the system is broken and I get this php warning

[Message: file_get_contents(.\app\application\views\smartytest.tpl): failed to open stream: No such file or directory
Filename: sysplugins/smarty_internal_resource_file.php
Line Number: 65]

and then blank page.
Second refresh only compiled blank page without warning.

CI 3's VIEWPATH outside the application's folder

Hi, a small update would be great to support the following:

Line 362: Can add VIEWPATH constant to the array of template locations to support CodeIgniter 3's "views outside the application folder.

PHP Error

I installed the plugin per the instructions and was getting the following error when going to the smartytest page.

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: module_template

Filename: libraries/MY_Parser.php

Line Number: 91

If the module doesn't exist then the variable "$module_template" never gets created. I added an empty string before the if statement:

$module_template = '';
        // If we have a module
        if ( ! empty($this->_module) )

It could also be added in the else clause or change the logic of the if file exists logic. by doing something like.

        // Does this module view actually exist?
        if ( isset($module_template) && file_exists($module_template))
        {
            $template = $module_template;
        }

I ended up going with the latter.

Does view path support folders?

I'am afraid there will be many template files in views/ folder. So I want to sort them into different folders. But I found if I put template files into folders under views/ like views/layouts/*, views/targets/* and views/partials/*, all the templates can't work well.

It Only work when I put all template files into views/ together. Did I miss something?

Smarty Default theme.

Hi, i am trying to change theme during a run using below method.

$this->parser->set_theme("themeName");

but it does not work, it is still loading the default theme

set in the smarty file in cofig directory which is default now in my case

$config['smarty.theme_name'] = "default";

Why this set_theme() method not working..

SmartyException : unable to write file

I can't get this error to go away, any help plz ? Im on ubuntu linux.

An uncaught Exception was encountered

Type: SmartyException

Message: unable to write file ./templates_c/wrt55215dc18cc9c8_54532485

Filename: /opt/lampp/htdocs/CMS/application/third_party/Smarty/sysplugins/smarty_internal_write_file.php

Line Number: 46

Backtrace:

File: /opt/lampp/htdocs/CMS/application/third_party/Smarty/sysplugins/smarty_internal_template.php
Line: 213
Function: writeFile

File: /opt/lampp/htdocs/CMS/application/third_party/Smarty/sysplugins/smarty_internal_templatebase.php
Line: 155
Function: compileTemplateSource

File: /opt/lampp/htdocs/CMS/application/libraries/MY_Parser.php
Line: 186
Function: fetch

File: /opt/lampp/htdocs/CMS/application/controllers/Smartytest.php
Line: 33
Function: parse

File: /opt/lampp/htdocs/CMS/index.php
Line: 292
Function: require_once

Bug Smarty error_reporting in MY_Parser.php

Hi,

if you don´t set the $error_reporting in your instance of the Smarty Class, the error_reporting level inside of the display() and the fetch() methods is turned off (for default), because its inicial value is null. If you use the tags {php}{/php} (Yes, I know that this is deprecated in Smart!) in your template, for example, the script will be interrupted at the point that you applied this tags. No error message is displayed. After this, any update you make in your template wouldn´t update the cache. Frozen the content with the error inside. To recover the updating, we need delete the cache. So, to mantain the consistency between Codeigniter and Smarty and resolves this problem (in part), I sugest the following inserts in MY_Parser.php, at the line 59, before the smarty->fetch() call:

    // Configure the $error_reporting of the Smarty equal as that is defined in the Codeigniter
    $this->CI->smarty->error_reporting = error_reporting();

with regards,
Dalmo.

PS.: How the parse_string() is an alias method of the string_parse(), to make easy future updates, I sugest you to modify the script to the following changes:

function parse_string($template, $data = array(), $return = FALSE, $is_include = false)
{
    return $this->string_parse($template, $data, $return, $is_include);
}

Cannot grab CI cached variables

The new version of CI has changed the cached variables from public to protected variables.
The following line from the MY_Parser.php file throws an error.

$data = array_merge($data, $this->CI->load->_ci_cached_vars);

Bug in My_Parser

in line 49 should be
$data = array_merge($data, $this->CI->load->_ci_cached_vars);
instead of
$data = array_merge($data, $this->load->_ci_cached_vars);

Config file not work.

I change something in config/smarty.php but it's not change.
I deleted all code in this file. It's not change too. Please fix.

Problem with cache config

When I use this library to render a same template with different data (just like a paged list), the result never change after first rendering. I try to set $config['cache_status'] to FALSE, then everything goes well.

So I am wondering what was done by the cache? Why different data was cached? Or if I missed something?

Undefined property: CI_Smarty::$_debug

test purpose........
A PHP Error was encountered

Severity: User Notice

Message: Undefined property: CI_Smarty::$_debug

Filename: Smarty/Smarty.class.php

Line Number: 738

Backtrace:

File: C:\xampp\htdocs\webtuts\application\third_party\Smarty\Smarty.class.php
Line: 1547
Function: _error_handler

File: C:\xampp\htdocs\webtuts\application\third_party\Smarty\Smarty.class.php
Line: 738
Function: trigger_error

File: C:\xampp\htdocs\webtuts\application\core\MY_Output.php
Line: 26
Function: __get

File: C:\xampp\htdocs\webtuts\index.php
Line: 315
Function: require_once
An uncaught Exception was encountered

Type: Error

Message: Call to a member function display_debug() on null

Filename: C:\xampp\htdocs\webtuts\application\core\MY_Output.php

Line Number: 26

Backtrace:

File: C:\xampp\htdocs\webtuts\index.php
Line: 315
Function: require_once

$_ci_cached_vars must be an array.

In MY_Loader there should be:

public $_ci_cached_vars = array();

Or you will get this:

A PHP Error was encountered

Severity: Warning

Message: array_merge(): Argument #1 is not an array

Filename: core/Loader.php

Line Number: 805

Allowed memory size of 536870912 bytes exhausted

Hi,

I received the following error:

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 370707 bytes) in ~application/third_party/Smarty/plugins/modifier.debug_print_var.php on line 46

But my phpinfo shows: memory_limit=512M

Which part is missing from my configuration?

Thanks for your help.

helper conflict img()

I have just started with codeigniter and thus a bit green / novice.
Loaded the CI-Smarty integrator and have the smartytest and smartytest/inheritance working just fine.
To get it working, I needed to remove the html helper in my config file as it conflicts with a function img() declaration.
Please advise remedy - thanks for the code assist, it looks like it will make life a little easier, although moving from $this->load->view() to $this->parser->parse() will take a bit of getting used to as I have only just grasped the first.
TIA
Rob

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.