Jump to content

Template <if> expressions


Mat Barrie

Recommended Posts


It would be nice, but it's not high on our list of priorities, since you can achieve the same thing with nested <if> statements.



True but it can get messy.


<if condition1>

	code1

<else>

	<if condition2>

		code2

	<else>

		<if condition3>

			code3

		<else>

			<if condition4>

				code4

			</if>

		</if>

	</if>

</if>

-vs-


<if condition1>

	code1

<elseif condition2>

	code2

<elseif condition3>

	code3

<elseif condition4>

	code4

</if>



I know the syntax of if and /if may be incorrect, but the idea is the same.

Not only does it appear more tidy but there are some instances where embedding if's within if's (from a lack of elseif) can make it more difficult to do something that an elseif would have made easier. I can't think of any examples off the top of my head but generally it's useful to have elseif.

Link to comment
Share on other sites

It would be nice to have <while> loops as well but the question is how far do you go with replication of PHP functions before it makes sense just to jump into <php></php> tags?

I'm having a similar issue with a complex loop that needs to track an iterating depth to build a nested list and I'm feeling guilty about jumping into using <php> tags :)

Link to comment
Share on other sites


True but it can get messy.



<if condition1>

	code1

<else>

	<if condition2>

		code2

	<else>

		<if condition3>

			code3

		<else>

			<if condition4>

				code4

			</if>

		</if>

	</if>

</if>

-vs-


<if condition1>

	code1

<elseif condition2>

	code2

<elseif condition3>

	code3

<elseif condition4>

	code4

</if>



I know the syntax of if and /if may be incorrect, but the idea is the same.

Not only does it appear more tidy but there are some instances where embedding if's within if's (from a lack of elseif) can make it more difficult to do something that an elseif would have made easier. I can't think of any examples off the top of my head but generally it's useful to have elseif.



I don't think there is any argument that else if is neater, I was only saying it isn't a high priority.
Link to comment
Share on other sites

Couldn't you just do a lot of this logic in the PHP source file that calls this template? Why would it need to be done in the template? Obviously you wouldn't want to be doing any style related stuff in the PHP, but logic issues can certainly be taken care of there.

Link to comment
Share on other sites


Obviously you wouldn't want to be doing any style related stuff in the PHP




Sorry for hijacking but that is my problem. Say I have a nested array and I pass this to the template. Now I need to build a nested list in the template. It's not straightforward to do this in template logic because working out when to add opening/closing tags and tracking the depth is a little more complex than a few nested loops. Add to that the fact I need to also display a different image depending on whether the list item is read/unread and we have a very grey area between what should and shouldn't be handled by the view.

Better I link to my issue I think as although it's related the OP has a slightly diffferent take - http://community.invisionpower.com/topic/305716-should-i-put-this-code-in-the-skin/
Link to comment
Share on other sites


Yeah, but if you've got a lot of things to test, you're looking at a HUGE pile of nesting, which I specifically noted I didn't like - in line is much better. I shudder to imagine the PHP code generated to handle it too.





Sorry - stupid post by me - considering I asked the same a month ago LOL

http://community.invisionpower.com/topic/303863-any-alternative-to-nested-if-statements

Link to comment
Share on other sites

I think you can still do all of that stuff in the source, it's not like even if these 'else if' or 'while' loops were added to the templates that it would give you abilities you can't do in the source. For things like determining when to have opening or closing tags, do the logic that determines that in the source, and set some sort of flag that tells the skin template to open or close the tag there. For read/unread images, have your PHP code check if the content is read or unread and set a flag accordingly, which the template can then look at to determine which image to display.

Link to comment
Share on other sites

Your template system doesn't support else if? Did it before? I could have sworn it did at some point. Maybe I'm spoiled with my template system... But it's hard to believe template logic is not complete in IPB's. Perhaps it's because the if/else is converted into ternary operators in the cache files?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...