Lack of interest Templates: check if property/class exists

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

Arty

Well-known member
This is a double request for 2 similar features for template system:
  • Ability to check if style property exists
  • Ability to check if class exists
Both abilities would allow style authors to add add-on specific code to styles by checking ether style property or class name.

Several suggestions for possible syntax:

1. For style properties only:
Code:
<xen:if is="@propertyName">
Currently this will trigger error because property does not exist

2. For anything:
Code:
<xen:if is="exists(property @propertyName)"> - for style properties
<xen:if is="exists(@propertyName)"> - also for style properties. @ before name gives away that it is style property
<xen:if is="exists(class XenForo_Application)"> - for class
or
Code:
<xen:if is="exists property @propertyName"> - for style properties
<xen:if is="exists @propertyName"> - also for style properties. @ before name gives away that it is style property
<xen:if is="exists class XenForo_Application"> - for class
This syntax could be extended further with ability to add more different checks based on keyword before item name.
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Use the xen tag property:

HTML:
<xen:if is="{xen:property propertyName}">
    Exists
<xen:else />
    Doesn't not exist
</xen:if>
=>Doesn't not exist

HTML:
<xen:if is="{xen:property mutedTextColor}">
    Exist
<xen:else />
    Doesn't not exist
</xen:if>
=>Exists

You will have probably to use this syntax in the official TMS when doing some search & replace

Edit: only in callbacks (see here)
 
Code:
<xen:if is="exists @propertyName"> - also for style properties. @ before name gives away that it is style property
<xen:if is="exists class XenForo_Application"> - for class

I'm curious, why do you want to check if a class exists? Is it to check if an addon is installed? (speaking of this it would be nice to have a xen tag to check if an addon is active or not)
If you really need a class or method check, you can create your own helper (requires between 5-15 minutes). Read this great tutorial of Fuhrmann and use this as helper function:

PHP:
    public static function checkClassOrMethod($class, $method == null)
    {
        if($method)
        {
            return method_exists($class, $method);
        }

        return class_exists($class);
    }
 
What's this syntax?
Curly syntax

{xen:if 'condition', 'if true', 'if false'}

You see this a lot where you want to use conditionals "inline"... e.g.

Code:
class="{xen:if {$message.isIgnored}, 'ignored', ''}"

Or of course:

Code:
class="{xen:if {$message.isIgnored}, 'ignored'}"
 
Curly syntax

{xen:if 'condition', 'if true', 'if false'}

You see this a lot where you want to use conditionals "inline"... e.g.

Code:
class="{xen:if {$message.isIgnored}, 'ignored', ''}"

Or of course:

Code:
class="{xen:if {$message.isIgnored}, 'ignored'}"
I meant the syntax with '== true', '==false'. The operator is inside the return value...
 
Back
Top Bottom