Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{include file="$array['block']['filename']"}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
LoP
Smarty n00b


Joined: 18 Apr 2003
Posts: 4
Location: Biale Blota, Poland

PostPosted: Fri Apr 18, 2003 11:41 am    Post subject: {include file="$array['block']['filename']"} Reply with quote

{include file="$block_zone"} <- this combination works pretty fine, but when in a section, i'd like to include other template file for every object in a loop. It would be very useful to use smarty with this code:

Code:

{section name=box loop=$_Blocks_right}
    {include file="$_Blocks_right[box].block_file"}
{/section}


This helps to have different content templates for different blocks. Maybe there is other way to do this, but I don't know it, anyone have done anything similar?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Apr 18, 2003 11:52 am    Post subject: Reply with quote

this is simple Smile

don't quote:
Code:

{section name=box loop=$_Blocks_right}
    {include file=$_Blocks_right[box].block_file}
{/section}


if you want to use such a construct inside a string use backticks (needs Smarty-2.5.0):

example:
Code:

{section name=box loop=$_Blocks_right}
    {include file="`$_Blocks_right[box].block_file`.tpl"}
{/section}


HTH
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LoP
Smarty n00b


Joined: 18 Apr 2003
Posts: 4
Location: Biale Blota, Poland

PostPosted: Sat Apr 19, 2003 11:30 am    Post subject: Reply with quote

yeah thanks i have already read that on smarty wiki's faq pages... but here comes another problem... maybe it is caused by bad design of array.

Code:

$block = array();
$zone = array();
while ( $row = $result->FetchRow() )
{
   $zone[] = $row['zone_name'];
   $i = 0;
   $result2 = $_EXPCMS->db->execute ( "select * from " . $_PREFIX ."_blocks where block_zone = '" . $row['zone_id'] . "' order by block_id asc" );
   if ( $result === false )
   {
         $_EXPCMS->raise_error ( __FILE__, __LINE__, "Error executing db query: " . $_EXPCMS->db->ErrorMsg() );
   }
   while ( $row2 = $result2->FetchRow() )
   {
      $block[$row['zone_name']][$i]['block_id'] = $row2['block_id'];
      $block[$row['zone_name']][$i]['block_name'] = $row2['block_name'];
      $block[$row['zone_name']][$i]['block_file'] = $row2['block_file'];
      $block[$row['zone_name']][$i]['block_order'] = $row2['block_order'];
      $modules = array();
      $mod_array = explode ( ",", $row2['block_modules'] );
      foreach ( $mod_array as $key => $val )
      {

         $modules[] = $val;

      }
      $block[$row['zone_name']][$i]['block_modules'] = $modules;
      $block[$row['zone_name']][$i]['block_zone'] = $row2['block_zone'];
      $block[$row['zone_name']][$i]['block_template'] = $row2['block_template'];
      $block[$row['zone_name']][$i]['block_active'] = $row2['block_active'];
      $i++;   
   }

}
$_EXPCMS->template->assign ( "Zone", $zone );
$_EXPCMS->template->assign ( "Block", $block );


This is the code, what i'd like to do is to have sth like this

Code:

{section name=zone loop=$Zone}
    {$Zone[zone]} // just the name of zone
    {section name=block loop=$Block}
        {Block.zone.block.block_name} // it is not correct, but this is how id like to get the data
        {Block.zone.block.block_file} // etc
    {/section}
{/section}


And the question is, how should i design the array?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Apr 19, 2003 1:10 pm    Post subject: Reply with quote

if i read the above right, then maybe (untested):
Code:

{foreach from=$Zone item=zone_name}
    {$zone_name} // just the name of zone
    {foreach from=$Block.$zone_name item=block}
        {$block.block_name}
        {$block.block_file}
    {/foreach}
{/foreach}



maybe this can also be done with {section}, but i like {foreach} more Smile ymmv
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LoP
Smarty n00b


Joined: 18 Apr 2003
Posts: 4
Location: Biale Blota, Poland

PostPosted: Sat Apr 19, 2003 5:05 pm    Post subject: Reply with quote

hehe :> cool Smile I've done it my way. this is what i've got

Code:

{foreach key=key item=zone from=$Zone}
   {if ( isset ( $Block[$zone] ) ) }   
      {section name=block loop=$Block[$zone]}
         {$Block[$zone][block].block_name} // etc   
      {/section}   
   {/if}
{/foreach}


heh, i've been fighting with it for about 30 minutes till i made it work :>

but i think that your way is much easier
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP