Smarty Templates - Multiple Classes - smarty

Here is my template code:
<li class="{$product.name}" {if $product.name == $filter_product.name}class=active{/if}">
I want to be able to set the $product.name as the class, and when the $product.name is the active filter also add the class "active"

You can only have one class attribute, but it can contain more than one class - separate them using a space. So in your example:
<li class="{$product.name}{if $product.name == $filter_product.name} active{/if}">

Found the answer myself:
{if $product.name == $filter_product.name}
<li class="active {$product.name}">
{else}
<li class="{$product.name}">
{/if}

Related

CS Cart - Show Three Level of Categories on Catalog and Top Category Page

For CS-Cart Multivendor, Version 4.15.2
How can we display 6 Sub-Categories-Level-1 and 3 Sub-Categories-Level-2 on mydomain.com/catalog page, similar to https://my.indiamart.com/ or https://dir.indiamart.com/
Then how to display 5 Sub-Categories-Level-1 image and name as displayed on https://dir.indiamart.com/
How can we display All Sub-Categories-Level-1 and 5 SubCategories-Level-2 on individual Category Page like below along with Level-1 and Level-2 Images
https://dir.indiamart.com/industry/builders-hardware.html
Finally Display SubCatetory-Level-2 and All Sub-Category-Level3 like
enter link description here
I think there is some modification required in views\categories\catalog.tpl and categories\components\subcategories.tpl.
Also some HTML and css related help is highly appreciated for user friendly view on all devices.
Thanks.
categories_multicolumns.tpl
{split data=$categories size=$columns|default:"3" assign="splitted_categories"}
{strip}
{foreach from=$splitted_categories item="scats"}
{foreach from=$scats item="category"}
{if $category}
{$href=$category|fn_form_dropdown_object_link:$block.type}
{if $category.main_pair}
{include file="common/image.tpl"
show_detailed_link=false
images=$category.main_pair
no_ids=true
image_id="category_image"
image_width=$settings.Thumbnails.category_lists_thumbnail_width
image_height=$settings.Thumbnails.category_lists_thumbnail_height
class="ty-subcategories-img"
}
{/if}
{$category.category}
{/if}
{/foreach}
{/foreach}
{/strip}
{capture name="mainbox_title"}{$title}{/capture}
subcategories.tpl
{if $subcategories}
{math equation="ceil(n/c)" assign="rows" n=$subcategories|count c=$columns|default:"3"}
{split data=$subcategories size=$rows assign="splitted_subcategories"}
<ul class="subcategories clearfix">
{hook name="categories:view_subcategories"}
{foreach from=$splitted_subcategories item="ssubcateg"}
{foreach from=$ssubcateg item=category name="ssubcateg"}
{if $category}
<li class="ty-subcategories__item">
<a href="{"categories.view?category_id=`$category.category_id`"|fn_url}">
{if $category.main_pair}
{include file="common/image.tpl"
show_detailed_link=false
images=$category.main_pair
no_ids=true
image_id="category_image"
image_width=$settings.Thumbnails.category_lists_thumbnail_width
image_height=$settings.Thumbnails.category_lists_thumbnail_height
class="ty-subcategories-img"
}
{/if}
<span {live_edit name="category:category:{$category.category_id}"}>{$category.category}</span>
</a>
</li>
{/if}
{/foreach}
{/foreach}
{/hook}
</ul>
{/if}

Spring boot Application with Thymeleaf. Using Constants to check hasAuthority

Defined constants in my class and using in UI to validate if user have the authority, show the menu to user else hide it. refer below code the way I implemented.
<li sec:authorize="hasAuthority('${T(com.sample.application.security.Privilege).ADMIN}')" class="nav-item" th:classappend="${template} == 'Home' ? 'active':''">
However, its not working as I expect. I was expecting thymeleaf to transform ${T(com.sample.application.security.Privilege).ADMIN} to ADMIN and verify it as hasAuthority('ADMIN') but thats not working. Is there any other way to do this validation in thymeleaf. Whats the best approach to get this implemented?
Update: Tried with assigning the constants to thymeleaf local variable as well. Didnt work either.
<ul class="navbar-nav" th:with="admin=${T(com.sample.application.security.Privilege).ADMINISTRATOR}, groupAdmin=${T(com.sample.application.security.Privilege).APPLICATION_GROUP_ADMIN}, basicUser=${T(com.sample.application.security.Privilege).APPLICATION_BASIC_USER}" >
<li sec:authorize="hasAuthority(${basicUser}) OR hasAuthority(${admin})" class="nav-item" th:classappend="${template} == 'home' ? 'active':''">
<a class="nav-link" href="/myApplication/User">Customer Home</a>
</li>......</ul>
After trying several ways. Below solution worked without any issue.
<ul class="navbar-nav">
<li sec:authorize="${hasAuthority(T(com.sample.application.security.Privilege).ADMINISTRATOR) OR hasAuthority(T(com.sample.application.security.Privilege).APPLICATION_GROUP_ADMIN)}" class="nav-item" th:classappend="${template} == 'home' ? 'active':''">
<a class="nav-link" href="/myApplication/User">Customer Home</a>
</li>

spring boot thymleaf i am trying to use conditional if in tymeleaf and tie it to a controller class to return true or false no pojo needed

i have a nav bar that i am using as a template.. see pic
if i am on any of the tabs then i want home to show. But if i am on the home page i don't want Home tab to show its redundant. i cant seem to figure out how to write the thymleaf code..
i have something like this the first line is what i am interested in fixing... can you please help with the controller part also i am sure i can do a model.addAttribute line in each method call and set the isActive to true except the home method i can set the isActive to false ... thank you
li th:text="${isActive} ? 'Home : "
<li th:text="${isActive} ? '<a th:href="#{/}">Home</a> : " </li>
<li><a th:href="#{/about}">About</a></li>
<li class="auctions">Auctions <i class="fas fa-caret-down"></i>
<ul>
<li>Current Auctions</li>
<li>Register</li>
</ul>
</li>
<li><a th:href="#{/contact}">Contact</a></li>
<li><a th:href="#{/locations}">Locations</a></li>
you can use this in controller:
model.addAttribute("isActive",true);
and use this in html code:
<li th:if="${isActive == null || !isActive}"><a th:href="#{/}">Home</a></li>
read more about Conditionals in Thymeleaf and simple conditionals if and unless

Cs-cart category menu descriptions

I am trying to show category description in category menu. Under each category link i would like to display a short description that is added through admin when creating the category.
This is the code in the tpl that displays the category menu:
{hook name="blocks:sidebox_dropdown"}{strip}
{assign var="foreach_name" value="item_`$iid`"}
{foreach from=$items item="item" name=$foreach_name}
{hook name="blocks:sidebox_dropdown_element"}
<li class="{if $separated && !$smarty.foreach.$foreach_name.last}b-border {/if}{if $item.$childs}dir{/if}{if $item.active || $item|fn_check_is_active_menu_item:$block.type} cm-active{/if}">
{if $item.$childs}
{hook name="blocks:sidebox_dropdown_childs"}
<div class="hide-border"> </div>
<ul>
{include file="blocks/sidebox_dropdown_chiled.tpl" items=$item.$childs separated=true submenu=true iid=$item.$item_id}
</ul>
{/hook}
{/if}
{assign var="item_url" value=$item|fn_form_dropdown_object_link:$block.type}
<a{if $item_url} href="{$item_url}"{/if} {if $item.new_window}target="_blank"{/if} class="my_main_navlinks">{$item.$name}</a>
</li>
{/hook}
{/foreach}
{/strip}{/hook}
It is not a right way to change the sidebox_dropdown.tpl file, because this file is used everywhere.
The right way is to create a new block template for categories.
Open this folder: /design/themes/[YOUR_SKIN]/templates/blocks/categories/
You will find (basically) 4 files:
categories_dropdown_horizontal.tpl
categories_dropdown_vertical.tpl
categories_multicolumn_list.tpl
categories_text_links.tpl
Create a new one and add any code you need. Put the sidebox_dropdown.tpl code inside your new file too.
After that just open Admin area -> Design -> Layouts. Open properties of the categories block and select your new file.

How to show content of a a specific URL in Smarty template?

Following is my code snippet from smarty template :
<div id="entrancelist">
<h2 class="heading">My Packages</h2>
{if $user_study_test_packages.test}
<ul class="entrancelist">
{foreach from=$user_study_test_packages.test item="user_test_packages" key=key}
<li>
<h4>{$user_test_packages.pack_name|capitalize:true}</h4>
{if $user_test_packages.pack_expiry_date1 >= $current_date }
<div class="fr"><span class="expiry">Expiry : {$user_test_packages.pack_expiry_date}</span></div>
{else}
<div class="fr"><span class="expiry_dt">This package is expired on {$user_test_packages.pack_expiry_date}.</span></div>
{/if}
<p class="descp">{$user_test_packages.test_pack_desc}</p>
<div class="srtest"> </div>
</li>
{/foreach}
</ol>
{else}
You haven't bought any online test packages
{/if}
</div>
Now what I want to do is reaplace the text "You haven't bought any online test packages" with the content of different URL say www.google.com But I'm not understanding how should I achieve this. Can anyone help me out in this issue? Thanks in advance.
Why not keep PHP separate from the template?
Maybe do this in your php code,
<?php
$gcontent = file_get_contents('http://www.google.com');
$smarty->assign('gcontent',$gcontent);
?>
Then you can use {$gcontent} in your template.
You can even use query string parameters with the URL if you wanted to. More info on the php function.
http://www.w3schools.com/php/func_filesystem_file_get_contents.asp
Something like this works for me in Smarty 3, but some might not consider it very elegant:
...
{else}
{file_get_contents('http://www.google.com/')}
{/if}

Resources