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

Вывести переменные в TWIG из строки


nekit555
 Share

Recommended Posts

Здравствуйте! Помогите пожалуйси разобраться с проблемой! Описал все ниже.

В базе у меня хранится html некоторых страниц.
В этом когде есть шорткоды:
 {{ chunk.review }}, {{ chunk.slider }}


 {{ chunk.review }} - это фактически

$data['chunk']['review'] = $this->load->controller('chunk/standart/review');

 

1. В контроллере я получаю код из базы и хочу всивить его в twig файл, через переменную
 

public function index() {
  $data['chunk']['review'] = $this->load->controller('chunk/standart/review');

  $this->load->model('layout/layout');

// Получаем из базы HTML код
  $data['page_html'] = html_entity_decode($this->model_layout_layout->getLayoutCode(6, 1));

  $this->response->setOutput($this->load->view('chunk/standart/index', $data));
}

2. В переменной $data['page_html'] хранится:

<h2>Заголовок</h2>
{{ chunk.review }}
 

3. Код файла index.twig:

{{ page_html }}

Проблема:

Вместо того, чтобы полулить:

<h2>Заголовок</h2>
<div class="review">
	<div class="review-item">
  	...
  	</div>
</div>

 

Я получаю на выхогде:

<h2>Заголовок</h2>
{{ chunk.review }}

 

Если в файл index.twig всивить {{ chunk.review }} все нормально подтягивается.

Edited by nekit555
Link to comment
Share on other sites


Метод должен вернуть данные

return $this->load->view(...

Link to comment
Share on other sites


Наконец-то решил вопрос.
Изменил код index.twig
 

{{ include(template_from_string(page_html)) }}

Чтобы функция template_from_string зарилиила, добавьте в файле Twig\Environment.php
 

$this->addExtension(new Twig_Extension_StringLoader());

 

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.