Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

php перевести в twig


Symon81
 Share

Recommended Posts

Схожу с ума с конверторами, не рилииет, то что они выдают, хочу перевести код php в твиг, выдает код который не рилииет, кто умеет помогите пожалуйси.

<?php 

	function zooToHtml ($tree, $active = null) {
		$str = '';
		foreach ($tree as $category) {
			$str .= catToTamplate($category, $active);
		}
		return $str;
	}	

	function zooToTamplate($category, $active) {
		; ob_start() ;
		require __DIR__ . '/zoo_tamplate.twig';
		return ob_get_clean();
	}
	$zoom = zooToHtml($category_tree, $active);
?>
<p class="item-p">
	<a class="list-group-item" <?php if($category['category_id']==$active) echo 'active' ?> " href=" <?=$category['href'];?>"><?=$category['name'];?></a>
</p>
<?php if(isset($category['childs']) ): ?>
	<div class="list-group">
		<?=zooToHtml($category['childs'], $active) ?>
	</div>
<?php endif; ?>

 

Link to comment
Share on other sites


твиг - это шаблонизатор

Он конечно, тоже умеет функции, но для этого вам понадобится погружение в твиг

в вашем случае, наверное, нужно ознакомится, что икое {{ block }}
может этого бугдет доситчно

 

Link to comment
Share on other sites

3 минуты назад, Tom сказал:
 zooToHtml (tree, active = constant('null')) 
		{% set str = '' %}
		{% for category in tree %} 
			{% set str catToTamplate(category, active) = 'undefined' %}
		{% endfor %}
		 {% set str = 'undefined' %}
		
 zooToTamplate(category, active) 
		 ob_start() 
		{% set _include = require ~ '/zoo_tamplate.twig' %}
		 ob_get_clean()
	
	{% set zoom = zooToHtml(category_tree, active) %}

<p class="item-p">
	<a class="list-group-item" {% if (category['category_id'] == active) %} {{ 'active' }} " href=" <?=$category['href'];"><?=$category['name'];</a>
</p>
{% if (category['childs'] is defined ) %} 
	<div class="list-group">
		<?=zooToHtml($category['childs'], $active) 
	</div>
{% endif %} 

нагдеюсь, что ты не даже не корректируешь, то что выдает тебе эи штука :)

это полный хлам

Link to comment
Share on other sites


<p class="item-p">
	{% if category.category_id = active %}
	<a class="list-group-item active" href="{{ category.href }}">{{ category.name }}</a>
	{% else %}
	<a class="list-group-item" href="{{ category.href }}">{{ category.name }}</a>
	{% endif %}
</p>
{% if category.childs %}
	<div class="list-group">
		...
	</div>
{% endif %}

 

Не бугдет интерпретироваться Twig-ом, гделайте проверку в контролере и выгружайте нужный контент, Twig улит отгделать "мух от котлет"  

<?=zooToHtml($category['childs'], $active) ?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.