Page 4 of 4

Re: [Tutorial] Convert to Twig Syntax

Posted: Fri Jun 22, 2018 2:45 pm
by MattF
Naguissa wrote:
Sun Jun 17, 2018 3:22 pm
3Di wrote:
Sun Jun 17, 2018 3:15 pm
On a side note, the extension's name can not be CamelCase'd if I am not wrong.
Interesting... I've not received any report about this, if so it will be a serious trouble....
Capitals are allowed.
https://www.phpbb.com/extensions/rules- ... extensions

However, keeping everything lowercase makes everything easier!

That's because if you use mixed case for the vendor and package naming, that has to be carried over exactly to the name-spacing of PHP files and in all references to the extension name such as in composer.json. Any mistakes and it will break. It's also worth noting that if developing on a Mac with a drive formatted to be case-insensitive (which is the default), then you won't realize your extension may be broken due to mistakes in getting the cases right until you deploy it to a UNIX based server.

Re: [Tutorial] Convert to Twig Syntax

Posted: Thu Jan 02, 2020 9:45 am
by bubbathegimp
A little confusion.....
I am all for anything that will improve performance on a shared server since my board is hosted on one.
Just installed the TWIG converter....
before you upload the modified files back to the proper directory, do you need to delete anything from the old directory.
I also noted that when some of the modified files are uploaded, they can be a little larger than the original,
so we might be trading a tad of server space for improved performance?

Re: [Tutorial] Convert to Twig Syntax

Posted: Thu Jan 02, 2020 12:42 pm
by david63
This is an extension writer's/style author's tool - not an extension that you would install on a live board.

Re: [Tutorial] Convert to Twig Syntax

Posted: Thu Mar 05, 2020 11:19 pm
by kinerity
Are both of these code examples right?

Code: Select all

$this->template->assign_block_vars('trackers', [
	'TRACKER_NAME'	=> $row['tracker_name'],
	'U_TRACKER'		=> $this->helper->route('kinerity_trackers_controller', ['page' => 'viewtracker', 't' => (int) $row['tracker_id']]),
]);

Code: Select all

{% for tracker in loops.trackers %}
<li>
	<a href="{{ tracker.U_TRACKER }}" role="menuitem">
		<i class="icon fa-file-o fa-fw icon-gray" aria-hidden="true"></i><span>{{ tracker.TRACKER_NAME }}</span>
	</a>
</li>
{% endfor %}

Re: [Tutorial] Convert to Twig Syntax

Posted: Thu Mar 05, 2020 11:42 pm
by 3Di
{% for tracker in loops.trackers %}
should be
{% for tracker in trackers %}

Also if it works is deprecated.
Also note that the loops. prefix is only needed in phpBB 3.1.x, and is not needed if you are writing for 3.2.x or later.

Re: [Tutorial] Convert to Twig Syntax

Posted: Fri Mar 06, 2020 12:17 am
by kinerity
Cool, thanks!

Re: [Tutorial] Convert to Twig Syntax

Posted: Sun Mar 08, 2020 8:48 pm
by kinerity
One more question - how would I convert this to Twig?

Code: Select all

<div class="<!-- IF articles.S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">

Re: [Tutorial] Convert to Twig Syntax

Posted: Sun Mar 08, 2020 11:03 pm
by AbaddonOrmuz
kinerity wrote:
Sun Mar 08, 2020 8:48 pm
One more question - how would I convert this to Twig?

Code: Select all

<div class="<!-- IF articles.S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
Something like:

Code: Select all

<div class="{{ articles.S_ROW_COUNT is even ? 'bg1' : 'bg2' }}">
Or

Code: Select all

<div class="bg{{ articles.S_ROW_COUNT is even ? '1' : '2' }}">
Not tested.

Re: [Tutorial] Convert to Twig Syntax

Posted: Mon Mar 09, 2020 2:18 am
by david63
kinerity wrote:
Sun Mar 08, 2020 8:48 pm
One more question - how would I convert this to Twig?

Code: Select all

<div class="<!-- IF articles.S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
You could always use the twig convertor extension to do it for you.

Re: [Tutorial] Convert to Twig Syntax

Posted: Mon Mar 09, 2020 4:09 am
by 3Di
david63 wrote:
Mon Mar 09, 2020 2:18 am
You could always use the twig convertor extension to do it for you.
Dunno if it is capable to handle ternary operators shorthands of if-then-else as above explained.

https://twig.symfony.com/doc/3.x/templa ... -operators
https://www.branchcms.com/learn/docs/de ... /operators

Re: [Tutorial] Convert to Twig Syntax

Posted: Mon Mar 09, 2020 10:46 am
by david63
3Di wrote:
Mon Mar 09, 2020 4:09 am
Dunno if it is capable to handle ternary operators shorthands of if-then-else as above explained.
Seems to have worked when I have tried it

Re: [Tutorial] Convert to Twig Syntax

Posted: Mon Mar 09, 2020 8:03 pm
by mrgoldy
I would suggest using loop.index instead, so you rely on twig rather than assigned loop variables.
And then use AbaddonOrmuz' suggestion: {{ loop.index is even ? 'bg1' : 'bg2' }}

Re: [Tutorial] Convert to Twig Syntax

Posted: Tue Mar 10, 2020 12:19 am
by 3Di
3Di wrote:
Thu Mar 05, 2020 11:42 pm
{% for tracker in loops.trackers %}
should be
{% for tracker in trackers %}

Also if it works is deprecated.
Also note that the loops. prefix is only needed in phpBB 3.1.x, and is not needed if you are writing for 3.2.x or later.
.loops prefix definitely does not work in phpBB 3.3 as a side note. At least here. :P

Re: [Tutorial] Convert to Twig Syntax

Posted: Tue Mar 10, 2020 12:29 am
by mrgoldy
There is a distinct difference between {% for x in loops.y %} and {{ loop.index }}.
loop. is a twig reference, while loops. is a prefix added to template block variables by phpBB.
For full documentation: https://twig.symfony.com/doc/3.x/tags/for.html

Re: [Tutorial] Convert to Twig Syntax

Posted: Tue Mar 10, 2020 12:44 am
by 3Di
mrgoldy wrote:
Tue Mar 10, 2020 12:29 am
... while loops. is a prefix ...
3Di wrote:
Tue Mar 10, 2020 12:19 am
.loops prefix
I know, it was not a reply to yours m8 - just a general clarification for the readers. :)