Access sub sub category, Shopware, Smarty - smarty

trying to solve issue with sub sub category access in Shopware with smarty, but not sure at all how to do it. Maybe someone knows.
<!-- THIS WORKS -->
{if $Category.sub}
{foreach $Category.sub as $sub}
<li>
<a href="#">
<span itemprop="name">{$sub.name}</span>
</a>
</li>
{/foreach}
{/if}
<!-- THIS DOESN'T WORK -->
{if $Category.sub.sub}
{foreach $Category.sub.sub as $subsub}
<li>
<a href="#">
<span itemprop="name">{$subsub.name}</span>
</a>
</li>
{/foreach}
{/if}

please check example above:
{foreach $Category.sub as $categoryItem}
{foreach $categoryItem.sub as $subsub}
<li>
<a href="#">
<span itemprop="name">{$subsub.name}</span>
</a>
</li>
{/foreach}
{/foreach}
Advanced example:
{foreach $Category.sub as $number => $categoryItem}
{if $categoryItem.childrenCount}
<ul id="submenu-{$number}" {if $categoryItem.flag}class="is--active"{/if}>
{if $categoryItem.cmsHeadline}
<li class="menu--list-item item--level-1">
<span class="menu--list-item-title">{$categoryItem.cmsHeadline}</span>
</li>
{/if}
{foreach $categoryItem.sub as $subcategory}
{if $subcategory.hideTop}
{continue}
{/if}
{$categoryLink = $subcategory.link}
{if $subcategory.external}
{$categoryLink = $subcategory.external}
{/if}
<li class="menu--list-item item--level-1{if $subcategory.flag} item--is-active{/if}">
{$subcategory.name}
</li>
{/foreach}
</ul>
{/if}
{/foreach}

Related

Smarty templating get second last element

Our designer wants to show only the parent of the last item in the breadcrumb. So if you are in My account > Addresses > Add new address, the breadcrumb should only show:
< Addresses
I'm not particularly known with Smarty, can this be done in some way?
This is the breadcrumb code I am working with at the moment:
<nav data-depth="{$breadcrumb.count}" class="breadcrumb">
<ul class="list-group list-group-flush list-group-horizontal m-0 p-0 d-flex">
{block name='breadcrumb'}
{foreach from=$breadcrumb.links item=path name=breadcrumb}
{block name='breadcrumb_item'}
<li class="list-group-item border-0">
<img src="{$urls.img_url}/icons/icon-back-account-arrow.svg" class="icon-svg" alt=""/>
<a href="{$path.url}" class="ms-2">
{$path.title}
</a>
</li>
{/block}
{/foreach}
{/block}
</ul>
</nav>
I am thinking of assigning a var to the last item and only showing that but I'm not sure how to go about it. Maybe something like:
{assign var=toShow value=($breadcrumb.count - 1)}
But I'm not sure how to use that in the loop.. Can someone help me in the right direction?

prestashop: How to display accessories of a product if product has properties?

In product.tpl below code needs some more effective conditions.
{if $features}
<section class="page_product_box toggle_frame datasheet" style="display:none;">
<h3 class="toggle">{l s='Data sheet'}<i class="icon-toggle icon-minus-sign-alt"></i></h3>
<div class="features">
{if isset($features) && $features}
{foreach from=$features item=feature}
<div id="feature-icon"><img class="feature" title="{$feature.detail}" src="{$img_ps_dir}f/{$feature["id_feature"]}.jpg" width="65" height="65"/></div>
{/foreach}
</div>
</section>
{/if}

Class for first element in smarty foreach

I'm trying to add some smarty to my template , to first element i want to give
<div class="item active">
and for next elements
<div class="item">
I tried to do something like this:
{foreach $imageCollection as $image key=slider}
{if $slider < 1}
<div class="item active">
<img class="img-responsive" src="{$image->getPath('1400x469')}" alt="caption1" />
<div class="carousel-caption">
{else}
<div class="item">
<img class="img-responsive" src="{$image->getPath('1400x469')}" alt="caption1" />
<div class="carousel-caption">
{/if}
{/foreach}
It's doesn't work, all elements are displaying with
<div class="item active">
use #first:
{foreach $imageCollection as $image}
<div class="item {if $image#first}active{/if}">
...
{/foreach}
The correct syntax for getting the index key in Smarty is as following:
{foreach from=$imageCollection item=image key=slider}
// Your code
{/foreach}

Laravel 4 base/master view

I've recently gotten some problems. There is an model from which I pull some data and things. There is a menu link that I want to be on every page I enter, so I've put it into the base/master view. But the problem is, I need to enter ->with blabla thing on every public function in every controller. How could I not do that? I mean is there anyway around it? I don't want to do that with thingy on every controller method/function. Here's my code:
#if ( Auth::guest() )
<li style="float: right;padding-right: 0">
<ul class="nav">
<li>
<a href="{{ URL::to('register') }}">
<i class="icon-black icon-plus">
</i>
<strong>
Register
</strong>
</a>
</li>
<li>
<a href="{{ URL::to('login') }}">
<i class="icon-black icon-lock">
</i>
<strong>
Log in
</strong>
</a>
</li>
</li>
</li>
</ul>
#else
<li class="divider-vertical">
</li>
<li style="float: right;padding-right: 0">
<div class="btn-group">
<div class="btn btn-primary">
<i class="icon-user">
</i>
{{ (Auth::user()->name) }}
</div>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
<span class="icon-caret-down">
</span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ URL::to('account/managment') }}">
<i class="icon-user">
</i>
Account Managment
</a>
</li>
<li>
<a href="{{ URL::to('account/managment/change_credentials') }}">
<i class="icon-lock">
</i>
Change Password
</a>
</li>
<li class="divider">
</li>
<li>
<a href="{{ URL::to('account/logout') }}">
<i class="icon-off">
</i>
Log out
</a>
</li>
</ul>
</div>
#endif
You can define a View Composer :
View::composer(array('your.first.view','your.second.view'), function($view)
{
$view->with('count', User::count());
});
Everytime you call your view, a user count will be bound to it automatically.
Edit:
About where to use it, it's up to you and it depends on your app, but you might use pp/start/global.php if you don't have a better place to put it. It just have to be executed before your those views.
#Antonio's answer is a good way to do this. You can also use View::share(); to accomplish this with a shorter code.
View::share(array(
'foo' => 'bar'
));

change header values based on variable codeigniter

I have the following in my header:
<div id="wrapper" class="homepage itemlist com_k2 category">
<div id="rt-header">
<div class="rt-container">
<div class="rt-grid-3 rt-alpha">
<div class="rt-block"></div>
</div>
<div class="rt-grid-9 rt-omega">
<div class="rt-fusionmenu">
<div class="nopill">
<div class="rt-menubar">
<ul class="menutop level1 ">
<li class="parent root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>
<li class="active root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
</ul>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
Now if you investigate the elements, you will find that there is an active flag in one of them. This makes sure that the currently seen page is highlighted in navigation bar. I want to know how can I change this based on view loaded? this is how I load views:
$this->load->view('layout/header');
$this->load->view('home');
$this->load->view('layout/footer');
So in this case the main navigation tab should be active.
Regards,
I completed something similar recently. Probably not the best way, but it works for me.
In your controller add this before your views
$data['contact'] = 'active';
Then pass the $data variable from the controller to the view
$this->load->view('header', $data);
And in your view add this to the list item
<li class="contact <?php if(isset($contact)) {echo $contact; }">
from the controller:
set names for your menus and put the loaded menu or page name in a variable as the following:
$data['active'] = 'menu1';
$this->load->view('layout/header',$data);
$this->load->view('home');
$this->load->view('layout/footer');
in the view:
<div id="wrapper" class="homepage itemlist com_k2 category">
<div id="rt-header">
<div class="rt-container">
<div class="rt-grid-3 rt-alpha">
<div class="rt-block"></div>
</div>
<div class="rt-grid-9 rt-omega">
<div class="rt-fusionmenu">
<div class="nopill">
<div class="rt-menubar">
<ul class="menutop level1 ">
<li class="<?php if(isset($active) && $active == 'menu1') echo 'active'; ?> parent root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu2') echo 'active'; ?> root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu3') echo 'active'; ?> root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu4') echo 'active'; ?> root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
</ul>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
Give each menu item a distinct class or id then do it via jQuery or js
<li class="kitchen root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="anotherclass root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="contact root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
Then for example in the contact page you'd simply do this via jQuery:
$(document).ready(function(){
$(".contact").addClass("active");
});

Resources