I'm using CS-Cart 4.1.x
I created an override for the block "design\themes\basic\templates\blocks\products\products_text_links.tpl"
The code that I see in the default file is:
{** block-description:text_links **}
<{if $block.properties.item_number == "Y"}ol{else}ul{/if} class="bullets-list">
{foreach from=$items item="product"}
{assign var="obj_id" value="`$block.block_id`000`$product.product_id`"}
{if $product}
<li>
{$product.product nofilter}
</li>
{/if}
{/foreach}
</{if $block.properties.item_number == "Y"}ol{else}ul{/if}>
What I need to do is just to replace the following line with the proper code to show the product's default image instead of its name:
{$product.product nofilter}
Any ideas?
Thanks
Try:
{foreach from=$items item="product"}
{if $product}
{assign var="obj_id" value="`$block.block_id`000`$product.product_id`"}
{include file="common/image.tpl" image_width=$block.properties.thumbnail_width image_height=$block.properties.thumbnail_height obj_id=$obj_id images=$product.main_pair href="products.view?product_id=`$product.product_id`"|fn_url}
{/if}
{/foreach}
Need to delete first element after all this statements, i try to add key=i to second foreach, and add {if $i!=0}, but it dont work for me, because i have multilevel system and after all if statements first $i is different for all pages.
{foreach from=$page.path item=e}
{assign var=element value=0}
{foreach from=$menu3 item=r}
{if $e.page_id==$r.page_id}{assign var=element value=$r}{/if}
{if $element._left < $r._left && $element._right > $r._right}
{if $r._level==$element._level+1 && $r._level==$page._level}
{$r.name}
{/if}
{/if}
{/foreach}
{/foreach}
P.S. Sorry for my English.
Add a name to you foreach and do something like this to get index
{foreach from=$items key=myId item=i name=foo}
{$smarty.foreach.foo.index} <!-- It will show index -->
{/foreach}
I assume you don't want to display first element in each of the menus you have, right?
{foreach from=$page.path item=e}
{assign var=first_skipped value=0}
{assign var=element value=0}
{foreach from=$menu3 item=r}
{if !$first_skipped}
{assign var=first_skipped value=1}
{else}
{if $e.page_id==$r.page_id}{assign var=element value=$r}{/if}
{if $element._left < $r._left && $element._right > $r._right}
{if $r._level==$element._level+1 && $r._level==$page._level}
{$r.name}
{/if}
{/if}
{/if}
{/foreach}
{/foreach}
I have a array of images in order:
1-3 are main images.
3+ are thumbnails.
Q) How can I split the thumbs on 2 lines.
E.g:
<div class="main-images">
{section name="i" loop=$images.rows}
{assign var="rows" value=$images.rows[i]}
{if $smarty.section.i.index <= 2}
<img />
{/if}
{/section}
</div>
<div class="thumbs-images">
{math assign=thumbs_count equation="total - other" total=$images.rowcount other=3}
{section name="i" loop=$images.rows}
{assign var="rows" value=$images.rows[i]}
{if $smarty.section.i.index >= 3}
<img />
{/if}
{/section}
</div>
So I need to add something {if $thumbs_count >= $smarty.section.i.index}<div style="clear:both" />{/if} so this appears half way through the second loop.
Managed to figure this out.
{math assign="total_row_split" equation="floor((total - main) / division)" total=$images.rows|#count division=2 main=3}
{counter start=0 print=false assign="thumbs_count"}
{section name="i" loop=$images.rows}
{assign var="rows" value=$images.rows[i]}
{if $smarty.section.i.index >= 3}
{if $thumbs_count == $total_row_split}<br style="clear:both" />{/if}
<a href="{$HOME}/get/image{$rows.filename.fvalue}" rel="fancy" title="{$rows.title.value|default:$product.name.fvalue}">
<img src="{$HOME}/get/image/120{$rows.filename.fvalue}" alt="{$rows.title.value|default:$product.name.fvalue} Picture" />
</a>
{counter print=false}
{/if}
{/section}
I'm learning PHP "on the go" as I edit a template for a website which I have to do at work, and I'm kinda lost. The original code looks like this:
<!-- start of top menubar -->
<table border="0" cellpadding="0" cellspacing="0" width="{$web_var_main_width}" align="center">
<tr style="background-color:#{$web_var_top_tabs_background};">
{php}
global $lang;
$this->assign('web_var_top_folder', $this->get_template_vars('web_var_top_folder_'.$lang));
{/php}
<td align="right" style="{if $web_var_top_tabs_image ne "" and $web_var_top_tabs_image ne 0}background:url(http://{$lang}.{$website_name}/{$RSwebPath}utilities/getScaledPicture.php?imageID={$web_var_top_tabs_image}&w={$web_var_top_tabs_image_x}&h={$web_var_top_tabs_image_y}&adj=d) top left repeat-y;{/if}background-color:#{$web_var_top_tabs_background_right};">
{if $folders_structure|#count gt 0}
{if $web_var_top_folder gt 0}
{section name=findtop loop=$folders_structure}
{if $folders_structure[findtop].key eq $web_var_top_folder}{assign var="top_menu" value=$folders_structure[findtop].childs}{/if}
{/section}
{if $top_menu|#count gt 0}
<table border="0" cellpadding="0" cellspacing="0" align="right">
<tr>
{if $web_var_top_font_size eq "small"}
{assign var="web_var_top_font_size" value="10px"}
{elseif $web_var_top_font_size eq "medium"}
{assign var="web_var_top_font_size" value="12px"}
{elseif $web_var_top_font_size eq "large"}
{assign var="web_var_top_font_size" value="14px"}
{elseif $web_var_top_font_size eq "extra large"}
{assign var="web_var_top_font_size" value="16px"}
{/if}
{section name=mytopsec loop=$top_menu}
<td width="5"></td>
{strip}
{if $top_menu[mytopsec].key eq $folders_selected[1]}
{assign var="topsel" value="1"}
<td bgcolor="#{$web_var_top_selected_tabs_color}" style="padding:6px 30px"><span style="font-family:{$web_var_top_font_family}; color:#{$web_var_top_font_color}; font-size:{$web_var_top_font_size}; font-weight:{$web_var_top_font_weight}; font-style:{$web_var_top_font_style}; text-decoration:none">{$top_menu[mytopsec].name}</span></td>
{else}
<td bgcolor="#{$web_var_top_tabs_color}" onMouseOver="this.style.backgroundColor='#{$web_var_top_tabs_hover}'; style.cursor='pointer'; style.cursor='hand'" onMouseOut="this.style.backgroundColor='#{$web_var_top_tabs_color}'" style="padding:6px 30px">{$top_menu[mytopsec].name}</td>
{/if}
{/strip}
{/section}
</tr>
</table>
{/if}
{/if}
{/if}
</td>
</tr>
<!-- end of top menubar -->
I have to send a folder ID which is the one the code scans into and shows all its childs.
And the function which scans the folders and lists them as menu items is this one:
<?
include_once "folderFunctions.php";
global $lang;
$global_deep=0;
$this->assign("folder_structure",getFolderChilds(0,$_SESSION["rs_domain_id"],$lang,"WEB",0,$global_deep));
$this->assign("folder_deep",$global_deep);
?>
Which uses the funcion GetFolderChilds from folderFunctions.php:
function getFolderChilds($identification,$website,$lang,$type,$local_deep,&$global_deep){
$child_list=array();
$childs = #mysql_query("SELECT `HB_IDENTIFICATION`,`HB_TITLE`,`HB_DESCRIPTION`,`HB_IMAGE_IDENTIFICATION`,`HB_LINK` FROM `hb_folders` WHERE `HB_PARENT_IDENTIFICATION` = ".$identification." AND `HB_DELETED`=0 AND `HB_PUBLISHED`=1 AND HB_WEBSITE_ID=".$website.(($type=='image')?(''):(" AND HB_LANGUAGE_ID='".$lang."'"))." AND HB_TYPE='".$type."' ORDER BY HB_ORDER");
$local_deep++;
if($local_deep>$global_deep&&#mysql_num_rows($childs)>0) $global_deep=$local_deep;
while($child = #mysql_fetch_assoc($childs)){
//$auxPermissions=getPermissions($_SESSION["rs_user_login"],$_SESSION["rs_user_pass"],$website,$child['HB_IDENTIFICATION'],'FOLDER');
//if($auxPermissions['read']==1){
$child_list[]=array("key"=>$child['HB_IDENTIFICATION'], "name"=>$child['HB_TITLE'], "desc"=>$child['HB_DESCRIPTION'], "image"=>$child['HB_IMAGE_IDENTIFICATION'], "link"=>$child['HB_LINK'], "childs"=>getFolderChilds($child['HB_IDENTIFICATION'],$website,$lang,$type,$local_deep,$global_deep));
//}
}
return $child_list;
}
And its output is something like this (tab changes color when mouse is on it, and so):
Well, that's what I figured out until now.
The thing is that I want to do a menu with these PHP functions, that is, creating the folders in the server and doing a loop which scans and shows them in my menu.
The thing is, that code uses tables, and has a lot of things which I don't need, such as image tabs and so (I just want to have a text menu with no images).
My question is, how can I implement the function to get the folders and list them not in a table, but in a list, so the output is something similar to this (I want to keep it as simple as posible in order to understand what is being done in any point)?
<header>
<ul class="navigation0">
<li>start</li>
<li>about us</li>
<li>contact</li>
</ul>
</header>
Which shows this:
Thanks a lot.
I believe I've solved it:
{php}
global $lang;
$this->assign('web_var_top_left_folder', $this->get_template_vars('web_var_top_left_folder_'.$lang));
{/php}
{if $folders_structure_left|#count gt 0}
{if $web_var_top_left_folder gt 0}
{section name=findtopleft loop=$folders_structure_left}
{if $folders_structure_left[findtopleft].key eq $web_var_top_left_folder}{assign var="top_left_menu" value=$folders_structure_left[findtopleft].childs}{/if}
{/section}
{if $top_left_menu|#count gt 0}
{if $web_var_top_font_size eq "small"}
{assign var="web_var_top_font_size" value="10px"}
{elseif $web_var_top_font_size eq "medium"}
{assign var="web_var_top_font_size" value="12px"}
{elseif $web_var_top_font_size eq "large"}
{assign var="web_var_top_font_size" value="14px"}
{elseif $web_var_top_font_size eq "extra large"}
{assign var="web_var_top_font_size" value="16px"}
{/if}
<ul class"leftmenu">
{section name=mytopsecleft loop=$top_left_menu}
{strip}
{if $top_left_menu[mytopsecleft].key eq $folders_selected[1]}
{assign var="topselleft" value="1"}
<li><span style="font-family:{$web_var_top_font_family}; color:#{$web_var_top_font_color}; font-size:{$web_var_top_font_size}; font-weight:{$web_var_top_font_weight}; font-style:{$web_var_top_font_style}; text-decoration:none">{$top_left_menu[mytopsecleft].name}</span></li>
{else}
<li onMouseOver="style.cursor='pointer'; style.cursor='hand'>{$top_left_menu[mytopsecleft].name}</li>
{/if}
{/strip}
{/section}
</ul>
{/if}
{/if}
{/if}
<div id="favorite-first" class="">
{foreach from=$arrSection key=k item=v}
{if $k==$selectedSection}
{$v}
{/if}
{/foreach}
</div>
<div id="favorite-toggle"><br></div>
<div id="favorite-inside" class="slideUp">
{foreach from=$arrSection key=k item=v}
{if $k==$selectedSection}
{else}
<div class="favorite-action" id="{$k}">{$v}</div>
{/if}
{/foreach}
</div>
If $arrSection array returns only one value (i.e $k). I need to hide div (favorite-toggle,favorite-inside) How can i do this in smarty
If $arrSection array returns only one value
{if count($arrSection) eq 1}
there is only one item
{else}
there is > one or zero items
{/if}
If you give the "foreach" a name argument you can access certain foreach properties:
{foreach from=$arrSection key=k item=v name=NAME}
Let's say the number of iterations in total:
$smarty.foreach.NAME.total
Then you now how often smarty will loop and if it's in your case only one time.