Jump to content

HTML logic (IFs)


marklcfc

Recommended Posts

This is regarding this blog post https://invisionpower.com/news/theme-tip-use-html-logic-to-display-content-to-specific-groups-r957/

Do we have any of IF codes as a replacement for these I used since IPB 3.

To place code everywhere but topic 69113

<if test="$this->request['t'] != 69113">DISPLAY INFO HERE</if>

To place code in topic 69113 specifically

<if test="$this->request['t'] == 69113">DISPLAY INFO HERE</if>

To place code inside the first post in each topic page

<if test="showAds:|:$post['post']['post_count'] % $this->settings['display_max_posts'] == 1">DISPLAY CODE HERE</if>

To place code in every topic in forum id 2

<if test="$this->request['f'] == 2">DISPLAY INFO HERE</if>

 

Link to comment
Share on other sites

  • 4 weeks later...
3 minutes ago, marklcfc said:

So is there no code to display everywhere but a certain topic. On 3.4 I did this to prevent code displaying on two topics


<if test="$this->request['t'] != 95676 && $this->request['t'] != 95852"> </if>

 

{{if \IPS\Request::i()->id != 1245 || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic'}}<ad here>[{endif}}

However, that won't work in the ad slots unless you download the appropriate plugin from the marketplace (advanced adverts or something along those lines) (it does work if you just modify templates though).

Link to comment
Share on other sites

Thanks. They are header and footer adverts and I've always placed them in globaltemplate so they display everywhere, so in that cause would I still need app forums and module forums, controller topic? Also if it is two topics I'd like to avoid how should the code be?

Link to comment
Share on other sites

33 minutes ago, marklcfc said:

Thanks. They are header and footer adverts and I've always placed them in globaltemplate so they display everywhere, so in that cause would I still need app forums and module forums, controller topic? Also if it is two topics I'd like to avoid how should the code be?

I added the app/controller/module so that it would only exclude the topic with that ID, and not anything else that happens to have the same ID. I had meant to say that in the post, but appear to have forgotten.

To have multiple topics excluded, replace the id check with

in_array(\IPS\Request::i()->id, array(1234, 5678, 55423))

(leaving the rest of the code there).

Link to comment
Share on other sites

 

13 minutes ago, Colonel_mortis said:

I added the app/controller/module so that it would only exclude the topic with that ID, and not anything else that happens to have the same ID. I had meant to say that in the post, but appear to have forgotten.

To have multiple topics excluded, replace the id check with


in_array(\IPS\Request::i()->id, array(1234, 5678, 55423))

(leaving the rest of the code there).

Just tried it and it works great, thanks alot :thumbsup:

How would I go about adding the following to it? Would I place it in front of your code and add the extra endif at the end? This is so it only appears to guests too

{{if \IPS\Member::loggedIn()->member_id === NULL}}
Link to comment
Share on other sites

52 minutes ago, marklcfc said:

 

Just tried it and it works great, thanks alot :thumbsup:

How would I go about adding the following to it? Would I place it in front of your code and add the extra endif at the end? This is so it only appears to guests too


{{if \IPS\Member::loggedIn()->member_id === NULL}}
{{if \IPS\Member::loggedIn()->member_id === NULL && ( !in_array(\IPS\Request::i()->id, array(1234, 5678, 55423)) || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic' ) }}<ad here>{{endif}}

 

Link to comment
Share on other sites

@Colonel_mortis say I'm using this

{{if \IPS\Member::loggedIn()->member_id === NULL && ( !in_array(\IPS\Request::i()->id, array(95676, 95852)) || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic' ) }}

what do I use to show to all members instead of guests, but keeping the not in topics part? I tried removing the first part but it wasn't having it

Link to comment
Share on other sites

On 18/07/2016 at 4:41 AM, marklcfc said:

@Colonel_mortis say I'm using this


{{if \IPS\Member::loggedIn()->member_id === NULL && ( !in_array(\IPS\Request::i()->id, array(95676, 95852)) || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic' ) }}

what do I use to show to all members instead of guests, but keeping the not in topics part? I tried removing the first part but it wasn't having it

You want something like

{{if !in_array(\IPS\Request::i()->id, array(95676, 95852)) || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic' }}

(getting rid of the member ID check and the && (as well as (), but they can be left)).

On 18/07/2016 at 1:55 PM, marklcfc said:

Also is there any code to show after 2nd post in each topic page

I'm not 100% sure, but I think you would have to make a theme hook or edit the template to achieve that.

Link to comment
Share on other sites

On 22/07/2016 at 0:20 AM, marklcfc said:

How to avoid showing on registration page? Does such code exist?

{{if (!in_array(\IPS\Request::i()->id, array(95676, 95852)) || \IPS\Request::i()->app != 'forums' || \IPS\Request::i()->module != 'forums' || \IPS\Request::i()->controller != 'topic') && (\IPS\Request::i()->app != 'core' || \IPS\Request::i()->module != 'system' || \IPS\Request::i()->controller != 'register') }}

 

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