Page 1 of 1
Add custom dynamic text into twig
Posted: Sat Nov 24, 2018 10:48 pm
by godly75
Is there a way to add custom dynamic html text into a twig file via {placeholder} ?
I would love to use for example text I created in a html module or in an information page of the site.
Or is the only way hard coded in the html?
Re: Add custom dynamic text into twig
Posted: Sun Nov 25, 2018 12:59 am
by OSWorX
You mean with dynamic:
1. refreshing itself (mean display always another text - like in a loop)
2. text which is displayed only once per page call - is static
Re: Add custom dynamic text into twig
Posted: Mon Nov 26, 2018 1:37 am
by godly75
Yes static but i mean for example the content of an information page as extra to a twig file
Re: Add custom dynamic text into twig
Posted: Mon Nov 26, 2018 3:35 am
by OSWorX
godly75 wrote: ↑Mon Nov 26, 2018 1:37 am
Yes static but i mean for example the content of an information page as extra to a twig file
(1)
Then load the information text via information model inside the controller you want/need.
Then assign the content to a variable and call that inside the template.
When you know the information id it is easy.
(2)
If not, create a small new module and select there the text you want.
If you do it this way, you can change easyily the text whenever there is a need.
Beside using such a new module, you can load everything you need in the output controller and template by the corresponding module controller (= 1 line in the target controller)
(3)
Or add a new event and call that.
You see, several ways to get what you want.
Re: Add custom dynamic text into twig
Posted: Tue Nov 27, 2018 7:30 am
by godly75
Thx I'll try to look into that
Re: Add custom dynamic text into twig
Posted: Fri Nov 30, 2018 5:07 pm
by godly75
This is an information page. How can I add for example info page id=9?
{{ header }}
<div id="information-information" class="container">
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
{% endfor %}
</ul>
<div class="row">{{ column_left }}
{% if column_left and column_right %}
{% set class = 'col-sm-6' %}
{% elseif column_left or column_right %}
{% set class = 'col-sm-9' %}
{% else %}
{% set class = 'col-sm-12' %}
{% endif %}
<div id="content" class="{{ class }}">{{ content_top }}
<h1>{{ heading_title }}</h1>
{{ description }}{{ content_bottom }}</div>
{{ column_right }}</div>
</div>
{{ footer }}
Re: Add custom dynamic text into twig
Posted: Fri Nov 30, 2018 6:29 pm
by OSWorX
godly75 wrote: ↑Fri Nov 30, 2018 5:07 pm
This is an information page. How can I add for example info page id=9?
As suggested in my former answer.
Anything else result in custom, paid job.
Re: Add custom dynamic text into twig
Posted: Sat Dec 01, 2018 8:32 pm
by godly75
I've send you some email but no reply?
Re: Add custom dynamic text into twig
Posted: Sat Dec 01, 2018 8:34 pm
by godly75
So the question stays, how can I reuse text from an existing info page with the _id=X number?
Is this custom or can I use this function?
How are info pages shown?
Re: Add custom dynamic text into twig
Posted: Sat Dec 01, 2018 8:49 pm
by xxvirusxx
Re: Add custom dynamic text into twig
Posted: Sun Dec 02, 2018 9:54 pm
by ocmta
First you should load information in the controller of the page where you want to use it, something like this:
Code: Select all
$information_id = 9;
$this->load->model('catalog/information');
$information = $this->model_catalog_information->getInformation($information_id);
if ($information) {
$data['information_title'] = $information['title'];
$data['information_description'] = $information['description'];
} else {
$data['information_title'] = '';
$data['information_description'] = '';
}
Then you can use information title and description in twig template, like this:
Code: Select all
{{ information_title }}
{{ information_description }}