Prestashop wrong pagination url - php

I'm using Prestashop v1.7.6.8. There is a pagination on category page and it shows correctly. But every link on pagination looks like:
https://mypage.com/3-BEDS
https://mypage.com/3-BEDS
https://mypage.com/3-BEDS
instead of:
https://mypage.com/3-BEDS?page=1
https://mypage.com/3-BEDS?page=2
https://mypage.com/3-BEDS?page=3
My pagination code:
{foreach from=$pagination.pages item="page"}
<li {if $page.current} class="current" {/if}>
{if $page.type === 'spacer'}
<span class="spacer">…</span>
{else}
<a rel="{if $page.type === 'previous'}prev{elseif $page.type === 'next'}next{else}nofollow{/if}" href="{$page.url}" class="{if $page.type === 'previous'}previous{elseif $page.type === 'next'}next{/if} {['disabled' => !$page.clickable, 'js-search-link' => true]|classnames}"{if $page.type === 'previous'} title="{l s='Previous' d='Shop.Theme.Actions'}"{elseif $page.type === 'next'} title="{l s='Next' d='Shop.Theme.Actions'}"{/if}>
{if $page.type === 'previous'}
<i class="material-icons">keyboard_arrow_left</i>
{elseif $page.type === 'next'}
<i class="material-icons">keyboard_arrow_right</i>
{else}
{$page.page}
{/if}
</a>
{/if}
</li>
{/foreach}
I think {$page.url} should give proper URL with page number?

Related

Symfony If Statements

I am hoping to get some assistance with Symfony 'if' statements.
Essentially I am trying to do, if the price value is equal to or greater than $500, display 'Free Shipping', if otherwise, display 'Click & Collect'.
This is a for a prestashop theme and I have the below coding after the initial if statement
{else}
{if $pricediplay ==> 500} {l s='Free Shipping!'}{/if}
{else}
{if $pricediplay ==< 499.99} {l s='Click & Collect'}{/if}
{/if}
The whole coding of this part is:
{if $option.total_price_with_tax && !$option.is_free &&
(!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))}
{if $use_taxes == 1}
{if $priceDisplay == 1}
{convertPrice price=$option.total_price_without_tax}
{if $display_tax_label}
{l s='(tax excl.)'}
{/if}
{else}
{convertPrice price=$option.total_price_with_tax}
{if $display_tax_label}
{l s='(tax incl.)'}
{/if}
{/if}
{else}
{convertPrice price=$option.total_price_without_tax}
{/if}
{else}
{if $pricediplay ==> 500}
{l s='Free Shipping!'}
{/if}
{else}
{if $pricediplay ==< 499.99}
{l s='Click & Collect'}
{/if}
{/if}
Any help would be greatly appreciated.
Thanks,
Cohen
It's hard to tell from your posting what you're trying to achieve. i suspect the changes you want might be something like this:
{if $option.total_price_with_tax && !$option.is_free &&
(!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))}
{if $use_taxes == 1}
{if $priceDisplay == 1}
{convertPrice price=$option.total_price_without_tax}
{if $display_tax_label}
{l s='(tax excl.)'}
{/if}
{else}
{convertPrice price=$option.total_price_with_tax}
{if $display_tax_label}
{l s='(tax incl.)'}
{/if}
{else}
{convertPrice price=$option.total_price_without_tax}
{/if}
{/if}
{else}
{if $priceDisplay >= 500}
{l s='Free Shipping!'}
{/if}
{else}
{if $priceDisplay <= 499.99}
{l s='Click & Collect'}
{/if}
{/if}
In smarty the comparison operators are like in many languages >= and <=. => has a different meaning in PHP, and smarty is translated into PHP before execution.
If it is supposed to be a template using twig if statements must be written as follow:
{% if ... %}
//your own logic...
{% endif %}
You can use both :
{% elseif ... %}
{% else %}
to make different cases.
You can set variables like this:
{% set var='toto' %}
and display a variable like this:
{{ var }}
And finally comparison operators are written as they are pronounced:
greater than or equal : >=
less than or equal : <=

Prestashop $category variable doesn't work within another if

I use Prestashop and I need to add a specific slideshow for the category->id 1 on the top of the category's products, and it's need to be within the code below:
I tried to insert this code:
{if category->id == '1'}
...
{/if}
Within this code:
{if isset($category)}
{if $category->id AND $category->active}
{if $scenes || $category->description || $category->id_image}
...
{if $scenes}
...
{include file="$tpl_dir./scenes.tpl" scenes=$scenes}
{if $category->description}
...
{if Tools::strlen($category->description) > 350}
...
{else}
{$category->description}
{/if}
...
{/if}
...
{else}
THERE'S WHERE I TRIED INSERT THE CODE
{/if}
{/if}
{/if}
{/if}
And it doesn't work.. why?
Regards,
Because you have placed in wrong position :)
{if isset($category)}
{if $category->id AND $category->active}
{if $scenes || $category->description || $category->id_image}
...
{if $scenes}
...
{include file="$tpl_dir./scenes.tpl" scenes=$scenes}
{if $category->description}
...
{if Tools::strlen($category->description) > 350}
...
{else}
{$category->description}
{/if}
...
{/if}
...
{else}
THERE'S WHERE I TRIED INSERT THE CODE (WRONG)
{/if}
{/if}
THERE'S WHERE YOU HAVE TO PLACE THE CODE
{if $category->id eq 1}
/* some stuff */
{/if}
{/if}
{/if}
For the next time fix the indentation and you reach the goal by yourself ;)
Insert it before the last
{else}

Multiple "Smarty" based errors after fixing an template

This is a rather misterious case. My "Prestashop" based website was working flawlessly, until this error popped up without editing anything for days:
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template
"/themes/default-bootstrap/product-list.tpl" on line 213 "{/foreach}"
unknown tag "foreachclose" <-- thrown in
/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 213
Content of the template file:
{*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* #author PrestaShop SA <contact#prestashop.com>
* #copyright 2007-2015 PrestaShop SA
* #license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if isset($products) && $products}
{*define number of products per line in other page for desktop*}
{if $page_name !='index' && $page_name !='product'}
{assign var='nbItemsPerLine' value=3}
{assign var='nbItemsPerLineTablet' value=2}
{assign var='nbItemsPerLineMobile' value=3}
{else}
{assign var='nbItemsPerLine' value=4}
{assign var='nbItemsPerLineTablet' value=3}
{assign var='nbItemsPerLineMobile' value=2}
{/if}
{*define numbers of product per line in other page for tablet*}
{assign var='nbLi' value=$products|#count}
{math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
{math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}
{math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}
<!-- Products list -->
<ul{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}">
{foreach from=$products item=product name=products}
{if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}
{if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}
{if $totModuloMobile == 0}{assign var='totModuloMobile' value=$nbItemsPerLineMobile}{/if}
<li class="ajax_block_product{if $page_name == 'index' || $page_name == 'product'} col-xs-12 col-sm-4 col-md-3{else} col-xs-12 col-sm-6 col-md-4{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLine == 0} last-in-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLine == 1} first-in-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModulo)} last-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 0} last-item-of-tablet-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 1} first-item-of-tablet-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 0} last-item-of-mobile-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 1} first-item-of-mobile-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModuloMobile)} last-mobile-line{/if}">
<div class="product-container" itemscope itemtype="https://schema.org/Product">
<div class="left-block">
<div class="product-image-container">
<a class="product_img_link" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url">
<img class="replace-2x img-responsive" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}" alt="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" title="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} itemprop="image" />
</a>
{if isset($quick_view) && $quick_view}
<div class="quick-view-wrapper-mobile">
<a class="quick-view-mobile" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
<i class="icon-eye-open"></i>
</a>
</div>
<a class="quick-view" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
<span>{l s='Quick view'}</span>
</a>
{/if}
{if (!$PS_CATALOG_MODE && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
<div class="content_price" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
<span itemprop="price" class="price product-price">
{hook h="displayProductPriceBlock" product=$product type="before_price"}
{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</span>
<meta itemprop="priceCurrency" content="{$currency->iso_code}" />
{if $product.price_without_reduction > 0 && isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
{hook h="displayProductPriceBlock" product=$product type="old_price"}
<span class="old-price product-price">
{displayWtPrice p=$product.price_without_reduction}
</span>
{if $product.specific_prices.reduction_type == 'percentage'}
<span class="price-percent-reduction">-{$product.specific_prices.reduction * 100}%</span>
{/if}
{/if}
{if $PS_STOCK_MANAGEMENT && isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span class="unvisible">
{if ($product.allow_oosp || $product.quantity > 0)}
<link itemprop="availability" href="https://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<link itemprop="availability" href="https://schema.org/LimitedAvailability" />{l s='Product available with different options'}
{else}
<link itemprop="availability" href="https://schema.org/OutOfStock" />{l s='Out of stock'}
{/if}
</span>
{/if}
{hook h="displayProductPriceBlock" product=$product type="price"}
{hook h="displayProductPriceBlock" product=$product type="unit_price"}
{/if}
</div>
{/if}
{if isset($product.new) && $product.new == 1}
<a class="new-box" href="{$product.link|escape:'html':'UTF-8'}">
<span class="new-label">{l s='New'}</span>
</a>
{/if}
{if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
<a class="sale-box" href="{$product.link|escape:'html':'UTF-8'}">
<span class="sale-label">{l s='Sale!'}</span>
</a>
{/if}
</div>
{if isset($product.is_virtual) && !$product.is_virtual}{hook h="displayProductDeliveryTime" product=$product}{/if}
{hook h="displayProductPriceBlock" product=$product type="weight"}
</div>
<div class="right-block">
<h5 itemprop="name">
{if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}
<a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" >
{$product.name|truncate:45:'...'|escape:'html':'UTF-8'}
</a>
</h5>
{capture name='displayProductListReviews'}{hook h='displayProductListReviews' product=$product}{/capture}
{if $smarty.capture.displayProductListReviews}
<div class="hook-reviews">
{hook h='displayProductListReviews' product=$product}
</div>
{/if}
<p class="product-desc" itemprop="description">
{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
</p>
{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
<div class="content_price">
{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
{hook h="displayProductPriceBlock" product=$product type='before_price'}
<span class="price product-price">
{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</span>
{if $product.price_without_reduction > 0 && isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
{hook h="displayProductPriceBlock" product=$product type="old_price"}
<span class="old-price product-price">
{displayWtPrice p=$product.price_without_reduction}
</span>
{hook h="displayProductPriceBlock" id_product=$product.id_product type="old_price"}
{if $product.specific_prices.reduction_type == 'percentage'}
<span class="price-percent-reduction">-{$product.specific_prices.reduction * 100}%</span>
{/if}
{/if}
{hook h="displayProductPriceBlock" product=$product type="price"}
{hook h="displayProductPriceBlock" product=$product type="unit_price"}
{hook h="displayProductPriceBlock" product=$product type='after_price'}
{/if}
</div>
{/if}
<div class="button-container">
{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.customizable != 2 && !$PS_CATALOG_MODE}
{if (!isset($product.customization_required) || !$product.customization_required) && ($product.allow_oosp || $product.quantity > 0)}
{capture}add=1&id_product={$product.id_product|intval}{if isset($product.id_product_attribute) && $product.id_product_attribute}&ipa={$product.id_product_attribute|intval}{/if}{if isset($static_token)}&token={$static_token}{/if}{/capture}
<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart', true, NULL, $smarty.capture.default, false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product-attribute="{$product.id_product_attribute|intval}" data-id-product="{$product.id_product|intval}" data-minimal_quantity="{if isset($product.product_attribute_minimal_quantity) && $product.product_attribute_minimal_quantity >= 1}{$product.product_attribute_minimal_quantity|intval}{else}{$product.minimal_quantity|intval}{/if}">
<span>{l s='Add to cart'}</span>
</a>
{else}
<span class="button ajax_add_to_cart_button btn btn-default disabled">
<span>{l s='Add to cart'}</span>
</span>
{/if}
{/if}
<a class="button lnk_view btn btn-default" href="{$product.link|escape:'html':'UTF-8'}" title="{l s='View'}">
<span>{if (isset($product.customization_required) && $product.customization_required)}{l s='Customize'}{else}{l s='More'}{/if}</span>
</a>
</div>
{if isset($product.color_list)}
<div class="color-list-container">{$product.color_list}</div>
{/if}
<div class="product-flags">
{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.online_only) && $product.online_only}
<span class="online_only">{l s='Online only'}</span>
{/if}
{/if}
{if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
{elseif isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
<span class="discount">{l s='Reduced price!'}</span>
{/if}
</div>
{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && isset($product.allow_oosp) && !$product.allow_oosp} label-danger{elseif $product.quantity <= 0} label-warning{else} label-success{/if}">
{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="label-warning">
{l s='Product available with different options'}
</span>
{else}
<span class="label-danger">
{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}
</div>
{if $page_name != 'index'}
<div class="functional-buttons clearfix">
{hook h='displayProductListFunctionalButtons' product=$product}
{if isset($comparator_max_item) && $comparator_max_item}
<div class="compare">
<a class="add_to_compare" href="{$product.link|escape:'html':'UTF-8'}" data-id-product="{$product.id_product}">{l s='Add to Compare'}</a>
</div>
{/if}
</div>
{/if}
</div><!-- .product-container> -->
</li>
{/foreach}
</ul>
{addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL}
{addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL}
{addJsDef comparator_max_item=$comparator_max_item}
{addJsDef comparedProductsIds=$compared_products}
{/if}
Someone pointed out that 3 lines of the mentioned file were missing. After I added them I got this array of errors popping up on my website but it was at least loading again:
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
Notice: Undefined index: totModulo in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 87
Notice: Trying to get property of non-object in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 87
Notice: Undefined index: totModuloTablet in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 88
Notice: Trying to get property of non-object in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 88
Notice: Undefined index: totModuloMobile in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 89
Notice: Trying to get property of non-object in
/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d
code on line 89
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
Warning: math: function call total not allowed in
/tools/smarty/plugins/function.math.php on line 53
I now had the idea of installing Prestashop again and copying the smarty plugin into the directory again to simply hope that it will fix the problem. It seems quite corrupted or something like that since I absolutely didn't touch mentioned php files. I also disabled all non-prestashop modules to verify that it wasn't caused by them.
Those three lines:
{math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}
Should be placed after the {foreach} in your template:
{math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
{math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}
<!-- Products list -->
<ul{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}">
{foreach from=$products item=product name=products}
{math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}
You placed them before the {foreach} while calling total=$smarty.foreach.products.total so total is undefined and math throws an error.

Smarty {capture} returns empty

I'm attempting to create a navigation while using smarty for the first time. I want to display all categories except one which I want to capture and use later on.
I got it to work and get the categories and put them in list. However that one category which is being captured, does not display where I want it to display.
my categories
Soccer //
subCat1 // those categories should be captured
subCat2 //
subCat3 //
Rugby
subCat1
subCat2
subCat3
Netball
subCat1
subCat2
subCat3
etc...
so my code goes like this:
<div>
<!-- deal with category levels -->
{if empty($category_level)}
{assign var="category_level" value=1}
{else}
{math equation="x + 1" x=$category_level assign="category_level"}
{/if}
{assign var="captured" value="false"}
{foreach from=$categories item="category"}
{if (strstr($category.name, 'Soccer') == true)}
{assign var="captured" value="y"}
{assign var="capItem" value="soccerCats"} <!-- used it to see whether the condition was met and this code has been run -- this has been assigned corerctly -->
{capture name="soccerCats" assign="soco"} <!-- start capturing if above condition was met -->
{/if}
{if $category.level == $category_level && $category.is_visible == "Yes"}
<ul>
<li class="{$category.name|htmlspecialchars}Cat">{$category.name|htmlspecialchars}<a class="mobileOnly"><i class="fa fa-angle-down fa-fw"></i></a>
{if !empty($category.children)}
<ul>
{assign var="categories" value=$category.children}
{if empty($category_level)}
{assign var="category_level" value=1}
{else}
{math equation="x + 1" x=$category_level assign="category_level"}
{/if}
{foreach from=$categories item="category"}
{if $category.level == $category_level && $category.is_visible == "Yes"}
<li>{$category.name|htmlspecialchars}</li>
{/if}
{/foreach}
{math equation="x - 1" x=$category_level assign="category_level"}
{assign var="category" value=0}
</ul>
{/if}
</li>
</ul>
{/if}
{if $captured == "y"}
{/capture} <!-- end the capture -->
{assign var="captured" value="n"}
{/if}
{/foreach}
{math equation="x - 1" x=$category_level assign="category_level"}
{assign var="category" value=0}
</div>
<!-- I tried to use both ways shown below to display the captured item -->
{$soco}
{$smarty.capture.soccerCats}
any idea why is this happening?
I don't think {capture} works inside {if} tags, and if does, I'd advise against it, for better code readability. Try something like this:
<div>
<!-- deal with category levels -->
{if empty($category_level)}
{assign var="category_level" value=1}
{else}
{math equation="x + 1" x=$category_level assign="category_level"}
{/if}
{foreach from=$categories item="category"}
{capture name="code"}
<ul>
<li class="{$category.name|htmlspecialchars}Cat">{$category.name|htmlspecialchars}<a class="mobileOnly"><i class="fa fa-angle-down fa-fw"></i></a>
{if !empty($category.children)}
<ul>
{assign var="categories" value=$category.children}
{if empty($category_level)}
{assign var="category_level" value=1}
{else}
{math equation="x + 1" x=$category_level assign="category_level"}
{/if}
{foreach from=$categories item="category"}
{if $category.level == $category_level && $category.is_visible == "Yes"}
<li>{$category.name|htmlspecialchars}</li>
{/if}
{/foreach}
{math equation="x - 1" x=$category_level assign="category_level"}
{assign var="category" value=0}
</ul>
{/if}
</li>
</ul>
{/capture}
{if (strstr($category.name, 'Soccer') != true)}
{$smarty.capture.code}
{else}
{$soccercats=$smarty.capture.code} {*Updated with #Borgtex's comment*}
{/if}
{/foreach}
</div>
{$soccercats}
The idea is that you capture everything and if the category is not 'soccer', you display the captured data; otherwise, you assign it to another capture, to use it in the end, outside the loop. The code assumes that there is a single soccer category, as you initially stated in your question.

Smarty dealing with array

Im trying to view contents of array on the page:
{foreach from=$entries key=i item=topic}
{if $topic.topic_style == question}
<li class="mail">
{$topic.title}
{$topic.tags}
</li>
{/if}
{/foreach}
$topic.tags is an array but i dont seem to be able to extract the contents to the page can anyone help?
Try this:
{foreach from=$entries key=i item=topic}
{if $topic.topic_style == question}
<li class="mail">
{$topic.title}
{foreach from=$topic.tags key=j item=tag}
{$tag}
{/foreach}
</li>
{/if}
{/foreach}
Where tag is the value of the tag name in the tags array().

Categories