[Tutorial] Convert to Twig Syntax

Discussion forum for Extension Writers regarding Extension Development.
User avatar
AbaddonOrmuz
Registered User
Posts: 368
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by AbaddonOrmuz » Wed Nov 29, 2017 4:44 am

MarkDHamill wrote:
Wed Nov 29, 2017 1:19 am

Code: Select all

var collapseImageIdAlt = '{LA_DIGESTS_COLLAPSE}';
var collapseImageIdTitle = '{LA_DIGESTS_COLLAPSE}';
Try:

Code: Select all

var collapseImageIdAlt = '{{ lang("DIGESTS_COLLAPSE") | escape("js") }}';
var collapseImageIdTitle = '{{ lang("DIGESTS_COLLAPSE") | escape("js") }}';
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
MarkDHamill
Registered User
Posts: 3431
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Wed Nov 29, 2017 1:01 pm

Thank you. This works. I suggest changing the first post, removing the addslashes option.
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: [Tutorial] Convert to Twig Syntax

Post by posey » Wed Nov 29, 2017 1:34 pm

I am not sure if there is an addslashes filter for Twig at the momoment, you can add one yourself.
Perhaps have a look at the Twig escape docs.

And for the language key, you need to add ' for language inputs,
eg: {L_DIGEST_COLLAPSE} becomes {{ lang('DIGEST_COLLAPSE') }}
and {SOME_VARIABLE} becomes {{ SOME_VARIABLE }}
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
MarkDHamill
Registered User
Posts: 3431
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Wed Nov 29, 2017 6:03 pm

Since my extension uses the ACP, I am trying to convert a common snippet of template code:

Code: Select all

<!-- BEGIN options -->
	<!-- IF options.S_LEGEND -->
		<!-- IF not options.S_FIRST_ROW -->
			</fieldset>
		<!-- ENDIF -->
		<fieldset>
			<legend>{options.LEGEND}</legend>
	<!-- ELSE -->

		<dl>
			<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt>
			<dd>{options.CONTENT}</dd>
		</dl>

	<!-- ENDIF -->
<!-- END options -->
This looks like it should work:

Code: Select all

{% for option in options %}
	{% if option.S_LEGEND %}
		{% if not loop.first %}
	</fieldset>
		{% endif %}
	<fieldset>
		<legend>{{ option.LEGEND }}</legend>
	{% else %}

	<dl>
		<dt><label for="{{ option.KEY }}">{{ option.TITLE }}{{ lang('COLON') }}</label>{% if option.S_EXPLAIN %}<br><span>{{ option.TITLE_EXPLAIN }}</span>{% endif %}</dt>
		<dd>{{ option.CONTENT }}</dd>
	</dl>

	{% endif %}
{% endfor %}
but this leaves out a </fieldset> before the </form> tag, so it is not valid. Something I am missing?
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
david63
Jr. Extension Validator
Posts: 14645
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by david63 » Wed Nov 29, 2017 6:48 pm

</fieldset> is an HTML tag not a Twig tag so whatever problem you have now you will have had in the past.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
MarkDHamill
Registered User
Posts: 3431
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Tue Dec 12, 2017 4:09 pm

thank you. Next question. How do I convert something like this?

Code: Select all

	<!-- INCLUDE {auth_tpl.TEMPLATE_FILE} -->
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3097
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by kasimi » Tue Dec 12, 2017 6:00 pm

See first post, Includes section, first example. Also have a look at the Twig Converter extension.

User avatar
MarkDHamill
Registered User
Posts: 3431
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Fri Dec 15, 2017 12:52 am

kasimi, you created an awesome extension that saves developers tons of time! I don't particularly want to learn more about the TWIG syntax until I have to dig into it.

I have some language files with the old syntax still embedded in it. Any chance you will update the extension to process these as well?
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3097
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by kasimi » Fri Dec 15, 2017 9:15 am

MarkDHamill wrote:
Fri Dec 15, 2017 12:52 am
I have some language files with the old syntax still embedded in it.
There's template syntax embedded in language files? Do you have an example?

User avatar
MarkDHamill
Registered User
Posts: 3431
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Fri Dec 15, 2017 12:47 pm

The messenger class uses template tags that go in the /language/en/email folder, so extensions that do emailing like mine must create them in our extensions. In 3.0 it was not as sophisticated as the full templating system. You could not use loops, for example. Perhaps this is no longer the case.

It wasn't a big deal to convert my language files so I did it manually, but you might want to add it to the files to convert.

Here's part of my digest tree as an example:

https://github.com/MarkDHamill/digests/ ... e/en/email

Your extension certainly saved me hours of tedious work, so thanks again!
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
Naguissa
Registered User
Posts: 239
Joined: Thu Mar 02, 2017 6:55 am
Location: Barcelona
Name: Naguissa
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by Naguissa » Sun Jun 17, 2018 2:46 pm

Hello,


I received this message trying to validate an extension:
{% include 'partials/star_rating.html' %}

Line 27: you should use the @vendor_extname/ prefix here.


I've tried:

Code: Select all

{% include '@vendor_extname/partials/star_rating.html' %}
{% include @vendor_extname'/partials/star_rating.html' %}
Giving me both a blank page (syntax error).


I've asked reporter but didn't receive any feedback.

So, anyone knows how to use it in twig templates? I know hot to use in old templates, but not on twig....



Thanks!

User avatar
david63
Jr. Extension Validator
Posts: 14645
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by david63 » Sun Jun 17, 2018 2:55 pm

Can you not use just {% include 'star_rating.html' %}
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Naguissa
Registered User
Posts: 239
Joined: Thu Mar 02, 2017 6:55 am
Location: Barcelona
Name: Naguissa
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by Naguissa » Sun Jun 17, 2018 2:58 pm

david63 wrote:
Sun Jun 17, 2018 2:55 pm
Can you not use just {% include 'star_rating.html' %}
It works (well, adding the "partials" folder), but seems to be against validation rules.

User avatar
3Di
Registered User
Posts: 12893
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by 3Di » Sun Jun 17, 2018 3:15 pm

The problem is your "partial" folder is outside of the "event" one, you should indicate the right route for it.

As per the @vendor_extname/ prefix, who is the vendor and what's the extension name :roll:

That should be
{% include '@gfksx_ThanksForPosts/partials/star_rating.html' %}

On a side note, the extension's name can not be CamelCase'd if I am not wrong.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Naguissa
Registered User
Posts: 239
Joined: Thu Mar 02, 2017 6:55 am
Location: Barcelona
Name: Naguissa
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by Naguissa » Sun Jun 17, 2018 3:22 pm

3Di wrote:
Sun Jun 17, 2018 3:15 pm
The problem is your "partial" folder is outside of the "event" one, you should indicate the right route for it.

As per the @vendor_extname/ prefix, who is the vendor and what's the extension name :roll:

That should be
{% include '@gfksx_ThanksForPosts/partials/star_rating.html' %}
Oh, my!!!

In old "html-comments-like" version it was a variable!

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....




Thanks!!!

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests

cron