CodeIgniter Forums
loading views as template variables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: loading views as template variables (/thread-25036.html)



loading views as template variables - El Forum - 11-28-2009

[eluser]bigtimslim[/eluser]
I'm new to using templates and quite sure how to go about this. I have a form that I want the designer to do whatever with. I feel like it would look better to just load the whole ting in the template as a variable. This gives me weird results. Thoughts?

Code:
function index()
    {
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('name', 'Name', 'required');
        $this->form_validation->set_rules('url', 'Url', 'required');
        $this->form_validation->set_rules('category', 'Category', 'callback_dropdown_check');
        $this->form_validation->set_rules('desc', 'Description', 'required|max_length[250]');
        $this->form_validation->set_rules('keyword', 'Keywords', 'required|max_length[50]');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            
        if ($this->form_validation->run() == FALSE) {
            $this->load->helper('form');
            //Get category list and prepate for dropdown
            $categories = $this->config->item('categories');
            foreach ($categories as $cat) {    $cats[$cat] = $cat; }
                    
            $data['message'] = $this->config->item('submit_site_message');
            $form['cats'] = $cats; //meow
            $data['form'] = $this->load->view('add_form_view', $form);
            //$data['form'] = $this->parser->parse('add_form_view', $form);

            //$this->load->view('add_view', $data);
            $this->parser->parse('add_template', $data);
        }
        else {
            if ($this->insert()) {
                redirect('add');
            } else {
                show_error('Site could not be added.');
            }
        }
    }

Code:
<html>
<head>
<link href="<?php echo base_url();?>public/css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="message">{message}</div>
<br />
<div id="add_form">{form}</div>
&lt;/body&gt;
&lt;/html&gt;



loading views as template variables - El Forum - 11-28-2009

[eluser]bigtimslim[/eluser]
I realize this might be a little weird for a designer not seeing the elements in the form. What is the most common way?


loading views as template variables - El Forum - 11-28-2009

[eluser]bigtimslim[/eluser]
Neverming.. I found the third load view parameter to return as string. :red:


loading views as template variables - El Forum - 01-15-2010

[eluser]hamzakhan[/eluser]
why dont u use any ci libray of template.