X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Help with Smarty (https://forum.x-cart.com/showthread.php?t=58461)

ADDISON 03-14-2011 10:05 AM

Help with Smarty
 
Sorry for posting here, but there is not section in this forum for Smarty discussions.

I would like to get a solution for this problem. I declare an associative array in a php file and assign it to a Smarty template

Code:

$products = array(
array("name" => "Adidas",      "products" => "12"),
array("name" => "Asics",      "products" => "8"),
array("name" => "Montrail",    "products" => "4"),
array("name" => "New Balance", "products" => "7"),
array("name" => "Puma",        "products" => "9"),
array("name" => "Salomon",    "products" => "11"),
array("name" => "Vasque",      "products" => "6"),
);

$smarty->assign("manufacturers", $manufacturers);


How can I create a table using Smarty, with a specified number of colums, as the following (let's say columns number is 3):

column 1 column 2 column 3
row 1: Adidas Asics Montrail
row 2: 12 8 4
row 3: New Balance Puma Salomon
row 4: 7 9 11
row 5: Vasque
row 6: 6

I know how to do it with 3 rows grouping in a table cell [name] and [products]. This version with 6 rows seems to be complex for me. I appreciate a solution on this.

Thanks!

Shamun 03-14-2011 10:19 AM

Re: Help with Smarty
 
Could you not use divs? Make Adidas 12 look to be on 2 rows, but have it in a block and just use 3 divs across each row like that?

ADDISON 03-14-2011 10:30 AM

Re: Help with Smarty
 
Someone more advanced in Smarty gave me this challenge. Of course I can use divs, but I need to do it in a table way as requested.

Quote:

Originally Posted by Shamun
Could you not use divs? Make Adidas 12 look to be on 2 rows, but have it in a block and just use 3 divs across each row like that?


Ene 03-14-2011 11:10 AM

Re: Help with Smarty
 
Quote:

Originally Posted by am2003
Sorry for posting here, but there is not section in this forum for Smarty discussions.

I would like to get a solution for this problem. I declare an associative array in a php file and assign it to a Smarty template

Code:

$products = array(
array("name" => "Adidas",      "products" => "12"),
array("name" => "Asics",      "products" => "8"),
array("name" => "Montrail",    "products" => "4"),
array("name" => "New Balance", "products" => "7"),
array("name" => "Puma",        "products" => "9"),
array("name" => "Salomon",    "products" => "11"),
array("name" => "Vasque",      "products" => "6"),
);

$smarty->assign("manufacturers", $manufacturers);


How can I create a table using Smarty, with a specified number of colums, as the following (let's say columns number is 3):

column 1 column 2 column 3
row 1: Adidas Asics Montrail
row 2: 12 8 4
row 3: New Balance Puma Salomon
row 4: 7 9 11
row 5: Vasque
row 6: 6

I know how to do it with 3 rows grouping in a table cell [name] and [products]. This version with 6 rows seems to be complex for me. I appreciate a solution on this.

Thanks!


Hmm, I'd try to adapt this code: http://www.smarty.net/forums/viewtopic.php?t=1391

cherie 03-14-2011 02:02 PM

Re: Help with Smarty
 
Maybe this will help:

http://smarty.incutio.com/?page=SmartyColumnsTutorial

ADDISON 03-17-2011 12:43 AM

Re: Help with Smarty
 
Here is the solution without using any web resources. I tried to make it as simple as I could.

Code:

{assign var="columns" value=3}
{assign var="i" value=0}
{assign var="totalmanufacturers" value=$manufacturers|@count}

{if $manufacturers}
        {if $columns gt 0}
                {assign var="rowloop" value=$totalmanufacturers/$columns}
                {assign var="restloop" value=$totalmanufacturers%$columns}
<table>
                {section name=rows loop=$rowloop}
        <tr>
                        {section name=rowname loop=$columns}
                <td>{$manufacturers[$i].name}</td>
                                {assign var="i" value=$i+1}
                        {/section}
        </tr>
        <tr>
                        {assign var="i" value=$i-$columns}
                        {section name=rowproducts loop=$columns}
                <td>{$manufacturers[$i].products}</td>
                                {assign var="i" value=$i+1}
                        {/section}
        </tr>
                {/section}
        <tr>
                {section name=rowname loop=$restloop}
                <td>{$manufacturers[$i].name}</td>
                        {assign var="i" value=$i+1}
                {/section}
        </tr>
                <tr>
                {assign var="i" value=$i-$restloop}
                {section name=rowproducts loop=$restloop}
                <td>{$manufacturers[$i].products}</td>
                        {assign var="i" value=$i+1}
                {/section}
        </tr>
</table>
        {else}
                The number of columns must be greater than 0
        {/if}
{else}
There are no manufacturers. Please create them.
{/if}



All times are GMT -8. The time now is 08:59 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.