Vai al contenuto

Useful codes


Back

Messaggi raccomandati

In IPS4, boolean checks are performed using special {{if}}, {{else}} and {{elseif}} tags. As with standard programming logic, if the expression evaluates to true, the block of code inside is executed. If it is not (and if there is another or elseif block that is checked instead of the true result). So, the logic block in the template might look like this:

{{if member.member_id == 3}}
    <! - If user has id 3, this will be shown ->
{{elseif member.member_id == 9}}
    <! - But if the user has id 9, this will be shown instead of ->
{{}} Еще
    <! - If the element is not ID 3 or 9 then this will show ->
{{ENDIF}}

Examples. I want to.

Check if user is logged in

{{if member.member_id}}
    <! - this will be shown if the user is logged in ->
{{ENDIF}}

Check if the user has been registered

{{if! member.member_id}}
    <! - this will show if the user is a guest ->
{{ENDIF}}

Check if the user id is one of x, y or z.
You can check as many values as you like; just add more numbers to the array.

{{if in_array (member.member_id, array (5, 28, 472))}}
    <! - Shows if member id is 5, 28 or 472 ->
{{ENDIF}}

Check if user is in group x.
Where x is the group ID. Note that this also checks for secondary member groups.

{{if member.inGroup ('x')}}
    <! - Shows if user is in group 'x' ->
{{ENDIF}}

Check if user has more than x posts.
In IPS4, all content in all applications is considered a "message".

{{if member.member_posts> 3}}
    <! - Shows if the user has more than 3 posts ->
{{ENDIF}}

Check if the user is an administrator.
Note that this also checks if any of the third party user groups have admin rights.

{{if member.isAdmin ()}}
    <! - Shows if the user is an administrator ->
{{ENDIF}}

Check if user is banned

{{if member.isBanned ()}}
    <! - Shows if the user is banned ->
{{ENDIF}}

Check if the current page is part of an application. X
You need to verify the application key. Most of them are obvious (for example, forums is a forum app), but there are others to be aware of. For custom/third party apps, ask the author what app key they are using.

- core = any system page that is not part of another application, such as search, login/registration, profiles, etc.
-cms=pages
- nexus = commerce

{{if request.app == 'forums'}}
    <! - Shows if the user is viewing any page in the Forums app ->
{{ENDIF}}

Check if a system parameter has a value of x
You can check if the system settings have a given value, although you will need to know the setting key used by the backend. Values may not be easy to check depending on their type - refer to our Customization Resources forum if you don't know how to check a particular setting.

{{if settings.auto_polling_enabled}}
    <! - Indicates if auto_polling_enabled is true (i.e. enabled) ->
{{ENDIF}}

Checking for a variable in a template has the value x.
Template bits in IPS4 can accept one or more variables from internal code. You can check the values of those values in the template to do something based on the value. This only works inside the template that the variable you're checking is passed into - they are not inherited.

{{if $ myVariable == 'some_value'}}
    <! - Shows if $ myVariable equals 'some_value' ->
{{ENDIF}}

Check if the current forum is a forum ID. X
In the forums app, you can check if the current page shows a forum with id x

{{if request.app == 'forums' && request.module == 'forums' && request.id == 3}}
    <! - Indicates if the user is in the forums application, browsing the forum with ID 3 ->
{{ENDIF}}

 

Link al commento
Condividi su altri siti

Crea un account o accedi per lasciare un commento

Devi essere un membro per lasciare un commento

Crea un account

Iscriviti per un nuovo account nella nostra community. È facile!

Registra un nuovo account

Accedi

Sei già registrato? Accedi qui.

Accedi Ora
  • Chi sta navigando   0 utenti

    • Nessun utente registrato visualizza questa pagina.
×
×
  • Crea Nuovo...

Informazioni importanti

Abbiamo inserito dei cookies nel tuo dispositivo per aiutarti a migliorare la tua esperienza su questo sito. Puoi modificare le impostazioni dei cookie, altrimenti puoi accettarli cliccando su continua. to insert a cookie message.