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

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

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

Post by RobiX »

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: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

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

Post by GanstaZ »

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.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
canonknipser
Registered User
Posts: 2096
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 »

@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 - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
AlfredoRamos
Recognised Extension Developer
Posts: 1302
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

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

Post by AlfredoRamos »

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 %}
Some of my phpBB extensions:
:chart_with_upwards_trend: SEO Metadata | Image Markdown | :shield: hCaptcha
:trophy: Check out all my validated extensions :trophy:

:penguin: Arch Linux user | Linux Boards :penguin:
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

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

Post by RobiX »

tnx for your answer maybe the best "SCRIPT_NAME in" is not bad ;)
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

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

Post by Tarantino »

If I want to have this but on a javascript code, can I use twig?
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

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

Post by mrgoldy »

No, you can not use TWIG syntax in Javascript.
However, JS has just as much versatility in writing statements like requested above.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

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

Post by Tarantino »

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
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

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

Post by mrgoldy »

-- double post --
Last edited by mrgoldy on Tue Jan 16, 2018 12:34 pm, edited 1 time in total.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

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

Post by mrgoldy »

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.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Post Reply

Return to “Extension Writers Discussion”