Using <!-- IF multi-line for better reading?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
RobiX
Registered User
Posts: 70
Joined: Thu Oct 05, 2017 9:59 am

Using <!-- IF multi-line for better reading?

Post by RobiX » Fri Nov 24, 2017 12:13 am

is it possible to write

Code: Select all

<!-- IF SCRIPT_NAME eq "a" or SCRIPT_NAME eq "b" or SCRIPT_NAME eq "z" -->
more readable like

Code: Select all

<!-- IF SCRIPT_NAME eq "a" or 
        SCRIPT_NAME eq "b" or 
        SCRIPT_NAME eq "z" -->

and if yes, how (last above one doesnt work)
Last edited by _Vinny_ on Fri Nov 24, 2017 4:35 am, edited 1 time in total.
Reason: Moved from [3.2.x] Support Forum

User avatar
GanstaZ
Registered User
Posts: 41
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Using <!-- IF multi-line for better reading?

Post by GanstaZ » Fri Nov 24, 2017 12:19 pm

More readable? It's a "Conditional Statement" not a method chaining. The first example is the way to go).

P.S. Haven't seen conditionals being used that way. Just try twig version of that code:

Code: Select all

{% if var == a or ... %}
Last edited by GanstaZ on Fri Nov 24, 2017 1:13 pm, edited 2 times in total.

User avatar
canonknipser
Registered User
Posts: 1303
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Using <!-- IF multi-line for better reading?

Post by canonknipser » Fri Nov 24, 2017 12:44 pm

@GanstaZ: It is very common to have a coding style not resulting in "spaghetti code", but in human readable code. And for humans shorter lines are better to read than long lines.
The primary question is if the internal "phpBB-template-to-twig"-convertor is able to ignore the line breaks or handle them as a whitespace, so a newline will be treated the same as a space or a tab.
If not, maybe transforming the statement to twig syntax will help you? -> viewtopic.php?f=461&t=2424606
Greetings
Frank
phpbb.de support team member
English is not my native language
New arrival - Extensions and scripts for phpBB
no support via PM or mail

User avatar
AbaddonOrmuz
Registered User
Posts: 249
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Using <!-- IF multi-line for better reading?

Post by AbaddonOrmuz » Fri Nov 24, 2017 7:22 pm

If you are planning using the new Twig syntax, you could use the in containment operator.

Code: Select all

{% if SCRIPT_NAME in ['a', 'b', 'c'] %}
{% endif %}
A proudly user of Arch Linux :: /r/sddm_themes

RobiX
Registered User
Posts: 70
Joined: Thu Oct 05, 2017 9:59 am

Re: Using <!-- IF multi-line for better reading?

Post by RobiX » Mon Nov 27, 2017 7:45 pm

tnx for your answer maybe the best "SCRIPT_NAME in" is not bad ;)

User avatar
Tarantino
Registered User
Posts: 590
Joined: Sat Feb 18, 2012 1:51 pm
Contact:

Re: Using <!-- IF multi-line for better reading?

Post by Tarantino » Tue Jan 16, 2018 2:30 am

If I want to have this but on a javascript code, can I use twig?

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

Re: Using <!-- IF multi-line for better reading?

Post by posey » Tue Jan 16, 2018 12:14 pm

No, you can not use TWIG syntax in Javascript.
However, JS has just as much versatility in writing statements like requested above.
''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
Tarantino
Registered User
Posts: 590
Joined: Sat Feb 18, 2012 1:51 pm
Contact:

Re: Using <!-- IF multi-line for better reading?

Post by Tarantino » Tue Jan 16, 2018 12:23 pm

I see. So if I put: var $text = {SCRIPT_NAME} will the $text have the {SCRIPT_NAME} path.
Because I wanted to do an if like this one: <!-- IF SCRIPT_NAME eq "a" --> but in javascript.

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

Re: Using <!-- IF multi-line for better reading?

Post by posey » Tue Jan 16, 2018 12:32 pm

-- double post --
Last edited by posey on Tue Jan 16, 2018 12:34 pm, edited 1 time in total.
''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
posey
Registered User
Posts: 638
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Using <!-- IF multi-line for better reading?

Post by posey » Tue Jan 16, 2018 12:32 pm

So you want to assign variables from PHP to the template, and use those variables inside a javascript?

Just assign the variable regularely in PHP, like you do with any other ($this->template->assign_vars(array()))
Then put the following in your template.

Code: Select all

	<script>
			var scriptName = '{{ SCRIPT_NAME | escape('js') }}';
	</script>
And now you can use the scriptName variable in your javascript file, if it's loaded on the same page.
''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.''

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: brunoais, Crizzo, nicofuma and 8 guests