Welcome Guest, Not a member yet? Register   Sign In
Ocular Layout Library - A Rails Inspired Layout Library
#31

[eluser]kilishan[/eluser]
[quote author="Deep Arora" date="1263502858"]Another question - can we use this library with CI's template parser class?

$this->parser->parse('blog_template', $data);

How can we call this method using Ocular?[/quote]

You know, I don't think it will work with Ocular. I don't ever use the parser (just PHP in views), so I didn't even think of that. I'll have to modify Ocular to support that. It should be a fairly simple addition, but it may be a day or two before I can get it working.
#32

[eluser]Deep Arora[/eluser]
[quote author="kilishan" date="1263503445"][quote author="Deep Arora" date="1263502858"]Another question - can we use this library with CI's template parser class?

$this->parser->parse('blog_template', $data);

How can we call this method using Ocular?[/quote]

You know, I don't think it will work with Ocular. I don't ever use the parser (just PHP in views), so I didn't even think of that. I'll have to modify Ocular to support that. It should be a fairly simple addition, but it may be a day or two before I can get it working.[/quote]

This will be awesome..this makes tasks like create login form tags and other data that, otherwise, needs to be hardcoded in views..fairly simple. With this, we can simply add an element and then provide in developer documentation that what tags to call in views.

If you can give me an idea what changes may be required, I can give it a shot today itself..
#33

[eluser]Deep Arora[/eluser]
Sorry for a flood of questions..but i want to structure the app in best optimized manner.

You mentioned of making some changes in Ocular/Matchbox if we want to use Ocular with matchbox. I checked the MY_Loader.php in Ocular and it has just one statement:
Code:
// Is Ocular loaded?
            if (class_exists('Template'))
            {
                return false;
            }
            ///@ END OCULAR CHANGES @///

I wonder where do I need to make edits with this code? Is it that this code need to be removed? Or is it that this code needs to be added in one of the matchbox library? If later, where exactly in matchbox library?

Thanks.
#34

[eluser]kilishan[/eluser]
My initial thought is to have a new method that simply allows you to set/clear a flag telling Ocular you want it to use the template parser.

Then, in the yield and block functions (unless you think it's needed for the layouts, then also the render function) it needs to check if it's using the parser, and then to use either a load->view call or a parser->parse call.

I should probably see if that can be refactored to all use a private function to render their elements...

If you get it working, that would be fantastic. Put it somewhere that I can get to it and I'll integrate into the library.
#35

[eluser]kilishan[/eluser]
[quote author="Deep Arora" date="1263504215"]Sorry for a flood of questions..but i want to structure the app in best optimized manner.

You mentioned of making some changes in Ocular/Matchbox if we want to use Ocular with matchbox. I checked the MY_Loader.php in Ocular and it has just one statement:
Code:
// Is Ocular loaded?
            if (class_exists('Template'))
            {
                return false;
            }
            ///@ END OCULAR CHANGES @///

I wonder where do I need to make edits with this code? Is it that this code need to be removed? Or is it that this code needs to be added in one of the matchbox library? If later, where exactly in matchbox library?

Thanks.[/quote]

That is the code that lets Ocular make the themes work (by returning false if the view can't be found, instead of kicking out a 404 error.) While I don't remember the details of Matchbox's MY_Loader file, if I remember correctly, it's using the original file as a basis and adding functions on top of it. If that's the case, I would imagine that it would be the same spot. Though, Matcbox is also trying to find files in different locations, so I'm not 100% sure. Wherever Matchbox tries to load a view and gets tired of looking and kicks back an error, I suppose. Smile

Sorry I can't be much more help on this one.
#36

[eluser]Deep Arora[/eluser]
[quote author="kilishan" date="1263504423"]My initial thought is to have a new method that simply allows you to set/clear a flag telling Ocular you want it to use the template parser.

Then, in the yield and block functions (unless you think it's needed for the layouts, then also the render function) it needs to check if it's using the parser, and then to use either a load->view call or a parser->parse call.

I should probably see if that can be refactored to all use a private function to render their elements...

If you get it working, that would be fantastic. Put it somewhere that I can get to it and I'll integrate into the library.[/quote]

Almost there...just a small problem left.

It is able to parse single variables. But if I define the data array:

Code:
$data = array(
            'content_resultset' => $result_set['posts'],
            'login_form_open' => $login_form_open,
                );

then it doesn't understand

Code:
{login_form_open}

..in the view.

This brings me to a point that I understand Ocular works slightly different from CI views. In normal CI view, we can form this data array and pass on to the views and then in view, simply capture elements by their names. Whereas in Ocular, I need to capture elements by defining

Code:
$data['element_name']


Am I doing something wrong here?

If this is how Ocular works, how would I parse the elements, as it doesn't understand

Code:
{data['login_form_open]}
#37

[eluser]kilishan[/eluser]
The way that I always work with Ocular is to use the
Code:
$this->template->set('name', 'value')
. This keeps an internal $data array that it passes to the views, blocks, etc. Is that how you're doing it? If so, I would think that it would work normally.

Or are you creating an array and then passing that array to the set() method? It almost sounds like the latter. The way it's designed is to just pass a single element and it's value into the set method. I've honestly never tried passing an array into it. Smile Maybe I should rewrite so it checks for an array and then merges that array with $this->data ?
#38

[eluser]Deep Arora[/eluser]
Wonderful..works using your approach better. I was forming the data arraoy in controller and then passing it to ocular. So in view, I had to call it using 2-dimensional array. But with your approach, it's much easier.

I will post the PARSER code in a bit..works wonderful!!

Thanks for all the help!! And hey, I switched to using themes, so that layout issues is not bothering me now Wink
#39

[eluser]kilishan[/eluser]
Awesome! Glad it's working for you. Looking forward to seeing your parser. Thanks for the work on that! I'll integrate it into main code as soon as I have a chance.
#40

[eluser]Deep Arora[/eluser]
Here you go..

In the Template.php, inside yield() function

Code:
// Grab the content of our view file
            if (empty($this->use_ci_parser)){
                $content = $this->ci->load->view($theme_folder . $this->current_view . '.' . $ext, $this->data, true);
            }
            else{
                if ($this->use_ci_parser) {
                    $content = $this->ci->parser->parse($theme_folder . $this->current_view . '.' . $ext, $this->data, true);
                }
                else {
                    $content = $this->ci->load->view($theme_folder . $this->current_view . '.' . $ext, $this->data, true);
                }
            }

..and inside block() function
Code:
if (empty($this->use_ci_parser)){
                $block_content = $this->ci->load->view($this->_check_view($block_name), $this->data, true);
            }
            else{
                if ($this->use_ci_parser) {
                    $block_content = $this->ci->parser->parse($this->_check_view($block_name), $this->data, true);
                }
                else {
                    $block_content = $this->ci->load->view($this->_check_view($block_name), $this->data, true);
                }
            }


Then in your controller function set this parameter whenever you want to use CI's parser:

Code:
$this->template->use_ci_parser = TRUE;

and in your view call either the pseudo code or php code to use your variable..

For example, in my controller, I define the following variable:

Code:
$var_login_form_open = "/home/login/";
        $login_form_open = form_open($var_login_form_open);
        $form_close = "</form>";

        $this->template->set('login_form_open', $login_form_open);
        $this->template->set('form_close', $form_close);
        $this->template->use_ci_parser = TRUE;

Now, in my view, I call the variable in either of the ways:

Code:
{login_form_open}

or

Code:
<?php echo $login_form_open;?>

Attached the update Template.php file as well.

Thanks again for all the help!!




Theme © iAndrew 2016 - Forum software by © MyBB