Welcome Guest, Not a member yet? Register   Sign In
Template Parser Limited?
#1

[eluser]Mischievous[/eluser]
I'm trying to run the template parser through a multidimensional array.... 3 dimensional to be exact. and it doesn't seem to like either the array setup or the parser is incapable of handling such operation.

ex: with 2 dimensional...
Code:
$query = $this->db->query("SELECT * FROM blog");

$this->load->library('parser');

$data = array(
              'blog_title'   => 'My Blog Title',
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => $query->result_array()
            );

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

I need a three dimensional

Code:
$query = $this->db->query("SELECT * FROM blog");

$this->load->library('parser');
$dataset = array(
             'category1' => $query1->result_array(),
             'category2' => $query2->result_array(),
             'category3' => $query3->result_array()
            );


$data = array(
              'blog_title'   => 'My Blog Title',
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => $dataset,
            );

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

If anyone has more information about the template parser I would appreciate it!
#2

[eluser]TheFuzzy0ne[/eluser]
Please post your view.
#3

[eluser]Mischievous[/eluser]
Code:
<div id='subpage_header'>
          <h1>{title}</h1>
          &lt;?=quick_tempimage('page_divider.png')?&gt;
          {breadcrumbs}
      </div>
      <div id="subpage_container">
{categories}
    {category}
        <div class="products_container">
                    <div class="products_questions">
                      <div class="products_top"><!– filler for ie –></div>
                      <div class="products_mid">
                        <div class="product_category"><a href="garrett/{category}/{subcategory}">{pd_name}</a></div>
                        <div class="gototop"><a href="#top"></a></div>
                      </div>
                      <div class="products_bot"><!– filler for ie –></div>
                    </div>
                    <div class="product_items">
                    <div class="product_categoryimg"><img src="product_images/{sku}sm.jpg" width="180" height="180" /></div>
                    <div class="products_categoryitems"><a href="garrett-gti.php">{pd_name}</a>
                    <p>{subcategory_description}</p>
                    <ul>
                        {product}
                          <li><a title="{pd_name}" href="/product/{pd_cartname}">{pd_name}</a></li>
                          {/product}
                    </ul>
                </div>
            </div>
        </div>
    {/category}
{/categories}
</div><!-Close subpage_container–>
#4

[eluser]Mischievous[/eluser]
Bump.... Sorry for that bump but... really need an answer on this.
#5

[eluser]TheFuzzy0ne[/eluser]
Is there any reason you can't just use a foreach loop for now?
#6

[eluser]Mischievous[/eluser]
No, I can definitely hard code it... would just like to have the separation between the code and template of the page....
#7

[eluser]TheFuzzy0ne[/eluser]
I know where you're coming from. I needed to take a break from what I was doing, so here's what I came up with.

./system/application/controllers/mdarray_parse_demo.php
Code:
&lt;?php

class Mdarray_parse_demo extends Controller
{
    function Mdarray_parse_demo()
    {
        parent::Controller();
        $this->load->library('parser');
    }
    
    function index()
    {
        $data['categories'] = $this->get_data();
        $this->parser->parse('mdarray_parse_demo', $data);
    }
    
    function get_data()
    {
        return array
        (
            array
            (
                'title' => 'Category 1',

                'products' => array
                (
                    array
                    (
                        'prod_title' => 'Hammer',
                        'prod_description' => 'For hitting stuff',
                        'sub_products' => array
                        (
                            array
                            (
                                'sp_title' => 'Glass Nails',
                            ),
                            array(
                                'sp_title' => 'Rubber Nails',
                            )
                        ),
                    ),
                    array
                    (
                        'prod_title' => 'Wheel Chair',
                        'prod_description' => 'It\'s a chair with wheels...',
                        'sub_products' => array
                        (
                            array
                            (
                                'sp_title' => 'Pedals',
                            ),
                            array(
                                'sp_title' => 'Nitrous Oxide',
                            )
                        ),
                    ),
                ),
            ),
            array
            (
                'title' => 'Category 2',
                
                'products' => array
                (
                    array
                    (
                        'prod_title' => 'Spade',
                        'prod_description' => 'For burying people',
                        'sub_products' => array
                        (
                            array
                            (
                                'sp_title' => 'Chloroform',
                            ),
                            array(
                                'sp_title' => 'Meat Clever',
                            )
                        ),
                    ),
                    array
                    (
                        'prod_title' => 'Rocket Launcher',
                        'prod_description' => 'For those times when you just need to de-stress',
                        'sub_products' => array
                        (
                            array
                            (
                                'sp_title' => 'Bill Gates',
                            ),
                            array(
                                'sp_title' => 'Amy Winehouse',
                            )
                        ),
                    ),
                ),
            ),
        );
    }
}

./system/application/views/mdarray_parse_demo.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
&lt;html &gt;
    &lt;head&gt;
        &lt;title&gt;Multi-dimensional Array Parse Demo&lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        {categories}
            <div>
                <h2>{title}</h2>
                <ul>
                    {products}
                        <li>{prod_title}<br />
                            {prod_description}
                            <ul>
                                {sub_products}
                                    <li>
                                        {sp_title}
                                    </li>
                                {/sub_products}
                            </ul>
                        </li>
                    {/products}
                </ul>
            </div>
        {/categories}
    &lt;/body&gt;
&lt;/html&gt;

Please see attached image for the result. I think the key is to ensure that none of the sub arrays have a key matching any of the keys in the parent arrays (hope that makes sense).
#8

[eluser]Mischievous[/eluser]
Ok... I'll be looking over your code and trying to figure out how the parser is going through that compared to what I have and why its not going through it... The difference that I am working with is that I am pulling a result_array from a mysql query.... not having a static array???


Erm... I'll look through it and post my results! I appreciate you taking your time to do that for me!
#9

[eluser]Phil Sturgeon[/eluser]
There is a massive issue with key names I spotted while working on my HelpfulParser. If anything has the same key name as an item higher up in the view data array, it will simply be ignored.
#10

[eluser]TheFuzzy0ne[/eluser]
[quote author="TheFuzzy0ne" date="1245453102"]I think the key is to ensure that none of the sub arrays have a key matching any of the keys in the parent arrays (hope that makes sense).[/quote]

Tongue

At least that confirms I'm not crazy. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB