[Tutorial] Convert to Twig Syntax

Discussion forum for Extension Writers regarding Extension Development.
User avatar
AbaddonOrmuz
Registered User
Posts: 239
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: 3335
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: 598
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: 3335
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: 13386
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: 3335
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: 2347
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: 3335
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: 2347
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: 3335
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.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 12 guests