Welcome Guest, Not a member yet? Register   Sign In
Sparks : Caching Template system
#9

[eluser]jbowman[/eluser]
I made a modification to Sparks for handling language setting.

I changed the changed the display and store functions to loop through the currently loaded language and create a $lang array.

So now if you have an application/lanaguage/english/template_lang.php that has this inside
Code:
$lang['template_email'] = 'Email';
$lang['template_password'] = 'Password';
$lang['template_register'] = 'Register now!';

You can have a block of your template/view look like

Code:
<div id="site_header_login">
            &lt;form method="post" action="/user/login"&gt;<$?=$lang['template_email'];?&gt;: &lt;input type="text" /&gt; <$?=$lang['template_password'];?&gt;: &lt;input type="password" /&gt; &lt;input type="submit" value="Login" /&gt;&lt;/form&gt;
            <a href="/user/register"><$?=$lang['template_register'];?&gt;</a>
        </div>

Note: I'm using the Sparks syntax to not cache my language strings, since they're dynamic depending on the user viewing the site.

Here's my updated functions.

Code:
/**
     *  Display the current cache file
     *  
     *  @access public
     *  @return object  A pointer to $this for chaining
     */
    function display()
    {
        
        $CI =& get_instance();

        extract($this->data, EXTR_SKIP); //EXTR_SKIP to avoid overwriting the $CI variable
        
       foreach ($CI->lang->language as $key => $val)
       {
                $lang[$key] = $val;
       }

        
        include($this->_cache_file_name());
        
        return $this;
        
    }

    /**
     *  Save this page to the cache
     *  
     *  @access public
     *  @return object  A pointer to $this for chaining
     */
    function store()
    {
                                
        $file = ($this->template_file == null) ? $this->content_file : $this->template_file;                
                                
        $__path = APPPATH.'views/'.$file;
        
        extract($this->data);
        
        $CI =& get_instance();

       foreach ($CI->lang->language as $key => $val)
       {
               $lang[$key] = $val;
       }

        
        ob_start();
        
        require($__path);
        
        $buffer = ob_get_contents();
        @ob_end_clean();
        
        $this->_write_to_cache($buffer);
        
        return $this;
        
    }


Messages In This Thread
Sparks : Caching Template system - by El Forum - 07-14-2007, 02:52 PM
Sparks : Caching Template system - by El Forum - 07-16-2007, 04:41 AM
Sparks : Caching Template system - by El Forum - 07-16-2007, 06:28 AM
Sparks : Caching Template system - by El Forum - 07-23-2007, 04:55 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 09:28 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:04 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:12 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:17 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 06:45 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:02 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:07 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:39 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:17 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:21 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:35 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 03:04 PM
Sparks : Caching Template system - by El Forum - 07-26-2007, 07:39 PM
Sparks : Caching Template system - by El Forum - 07-27-2007, 01:19 AM
Sparks : Caching Template system - by El Forum - 07-27-2007, 05:26 AM
Sparks : Caching Template system - by El Forum - 07-27-2007, 07:10 AM
Sparks : Caching Template system - by El Forum - 08-02-2007, 07:15 AM
Sparks : Caching Template system - by El Forum - 08-13-2007, 12:53 PM
Sparks : Caching Template system - by El Forum - 09-24-2007, 05:32 AM
Sparks : Caching Template system - by El Forum - 09-24-2007, 01:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB