1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lack of Interest Templates: check if property/class exists

Discussion in 'Closed Suggestions' started by Arty, Apr 13, 2013.

  1. Arty

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

    CyberAP Well-Known Member

    You may use another syntax:

    Code:
    {xen:if '@property', '== true', '== false'}
     
  3. cclaerhout

    cclaerhout Well-Known Member

    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)
     
  4. cclaerhout

    cclaerhout Well-Known Member

    What's this syntax?
     
  5. cclaerhout

    cclaerhout Well-Known Member

    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);
        }
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    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'}"
     
    dwdmadmac likes this.
  7. cclaerhout

    cclaerhout Well-Known Member

    I meant the syntax with '== true', '==false'. The operator is inside the return value...
     
    James likes this.
  8. Mike

    Mike XenForo Developer Staff Member

    I think he just meant the behavior to use when it was true or false.
     
    CyberAP likes this.
  9. cclaerhout

    cclaerhout Well-Known Member

    Mike, do you think it would be technically possible (without any extra db request) to have in a future release a function to check if an addon is active or not?
     

Share This Page