Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Help with Smarty

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-14-2011, 10:05 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Default 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!
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote
  #2  
Old 03-14-2011, 10:19 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default 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?
__________________
- Shane Munroe
Reply With Quote
  #3  
Old 03-14-2011, 10:30 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Default 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?
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote
  #4  
Old 03-14-2011, 11:10 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default 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
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #5  
Old 03-14-2011, 02:02 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: Help with Smarty

Maybe this will help:

http://smarty.incutio.com/?page=SmartyColumnsTutorial
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #6  
Old 03-17-2011, 12:43 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Default 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}
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:43 PM.

   

 
X-Cart forums © 2001-2020