Link to home
Create AccountLog in
Avatar of re-searcher
re-searcherFlag for United States of America

asked on

What's equal of these smarty codes in php

Hello,

Would you mind tell me what's equal of these commands in php?
i convert it to php but it's not work, please, if you know tell me what's equal of these commands in php.
<li class="item{if isset($currentCategoryId) && ($node.id == $currentCategoryId)} selected{/if}{if $node.children|@count > 0} submenu{/if}{if isset($last) && $last == 'true'} last{/if}">
	<div class="categ_sel_left"></div><div class="categ_sel_right"></div>
	<a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
	{if $node.children|@count > 0}
		<ul class="subcategories">
		{foreach from=$node.children item=child}
			<li><a href="{$child.link|escape:html:'UTF-8'}">{$child.name|escape:html:'UTF-8'}</a></li>
		{/foreach}
		</ul>
	{/if}
</li>

Open in new window


{foreach from=$blockCategTree.children item=child name=blockCategTree}
		{if $smarty.foreach.blockCategTree.last}
			{include file="$branche_tpl_path" node=$child last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child}
		{/if}
	{/foreach}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Amar Bardoliwala
Amar Bardoliwala
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
<?php
if (isset($currentCategoryId) && ($node.id == $currentCategoryId)) {...}
if (count($node.children) > 0) {...} //or you can use more descriptive
if (!empty($node.children)) {...}
if (isset($last) && $last == 'true') {...} // Are you sure you want to check string instead of bolean?
if (!empty($last)) // this is more descriptive in case $last is boolean, see empty statement in PHP manual
?>

In case of |escape see Smarty manual to know what PHP function is used with which parameters.

<?php
foreach ($node.children as $child) {...}
?>

For the second foreach try to look at ArrayIterator from SPL functions domented on PHP manual.
Avatar of re-searcher

ASKER

#amar_bardoliwala,
would you mind tell second code in php?

#sharkodlak
I need complete answer not ....
Hello re-searcher,

you second code seems to include tpl file and not php file.

following is what it should be but I am not sure if it will work 100% for you

 
<?php
	for($i = 0; $i < count($blockCategTree["children"]); $i++)
	{
		$child = $blockCategTree["children"][$i];
		
		if($i == count($blockCategTree["children"]) - 1)
		{
			include "$branche_tpl_path?node=$child&last=true";
		}
		else
		{
			include "$branche_tpl_path?node=$child&last=true";
		}
	}
?>

Open in new window


Also it seems that you are working with prestashop ..

So as I told you, you should get its php equivalent from templates_c directory of your smarty.

Hope this will help.

Thank You.

Amar.
Yes, it's for presta.

previous code not work because i don't have $node and i don't want to work with smarty.


i want to list all categories with their sub categories. and i need to specify tree_depth.
how can i parse following array:
Array ( [id] => 1 [link] => http://shopping.prj/category.php?id_category=1 [name] => [desc] => [children] => Array ( [0] => Array ( [id] => 2 [link] => http://shopping.prj/category.php?id_category=2 [name] => category 1 [desc] => [children] => Array ( [0] => Array ( [id] => 5 [link] => http://shopping.prj/category.php?id_category=5 [name] => subcat 2 [desc] => [children] => Array ( ) ) [1] => Array ( [id] => 6 [link] => http://shopping.prj/category.php?id_category=6 [name] => subcat 2 [desc] => [children] => Array ( ) ) ) ) [1] => Array ( [id] => 3 [link] => http://shopping.prj/category.php?id_category=3 [name] => category 2category 3 [desc] => [children] => Array ( [0] => Array ( [id] => 7 [link] => http://shopping.prj/category.php?id_category=7 [name] => subcat 1 [desc] => [children] => Array ( ) ) [1] => Array ( [id] => 8 [link] => http://shopping.prj/category.php?id_category=8 [name] => subcat 2 [desc] => [children] => Array ( ) ) ) ) [2] => Array ( [id] => 4 [link] => http://shopping.prj/category.php?id_category=4 [name] => category 3 [desc] => [children] => Array ( ) ) ) )

Open in new window

Hello re-searcher,

I just gave you php version of that code... In PHP, you might need to make little adjustments.

You can assign your array above to $node and see what happens..

Experts here should be able to help you if you give your current code here and give details about what you want to achieve exactly with that code like trying to create menu or trying to display tree or something else.

Also you might get some help from forums of presta shop.

Hope this will help you.

Thank You.

Amar.

I found it my self,
with some change to your code i finish my job...