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

XF 1.2 Standard Value for Custom Fields

Discussion in 'XenForo Questions and Support' started by katsulynx, Dec 28, 2013.

  1. katsulynx

    katsulynx Well-Known Member

    Is it possible to give a custom user field a standard value, which is automatically assigned to the field if left empty or gets assigned back to it if the field is emptied by the user?
     
  2. Mike

    Mike XenForo Developer Staff Member

    In general, that's no an option.
     
  3. katsulynx

    katsulynx Well-Known Member

    Is there a way to determine wether a profile field is filled in or not? As you can call it inside the templates with the {$visitor.customFields.fieldId}-command, you would "simply" need to detect if it is filled or not. I want to create an option to fill a custom field with an url pointing to an image-url, which is then assigned as background for the forum, but by now it does not display any background for the forum, if the field is not filled.
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    This should work for the check: <xen:if is="{$user.customFields.field_id}">
     
    katsulynx likes this.
  5. katsulynx

    katsulynx Well-Known Member

    I've done it with $visitor.customFields.11 (ID is correct), visitor to get the current user logged in (or not).

    This is the code snippet:
    Code:
    <style type="text/css">
        html, .level_1, .secondaryContent h3, .sectionHeaders, .application_container h1, .location_headline  {
            <xen:if is="{$visitor.customFields.11}">
                    background: url({$visitor.customFields.11}) repeat fixed center !important;
                }
                .nodeIcon {   
                    background: url(/styles/uniform/xenforo/xenfocus/f_icon.png), url({$visitor.customFields.11}) fixed !important;
                }
            </xen:if>
            <xen:else>
                    background: url(/styles/kitsunebi/xenforo/kitsunebi_IMG/background.png) repeat fixed center !important;
                }
                .nodeIcon {   
                    background: url(/styles/uniform/xenforo/xenfocus/f_icon.png), url(/styles/kitsunebi/xenforo/kitsunebi_IMG/background.png) fixed !important;
                }
            </xen:else>
    </style>
    
    However, I get a blank background with neither of those pictures.
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    Consider using background: url('@imagePath/path/to/image.png')
     
  7. katsulynx

    katsulynx Well-Known Member

    Did, but didn't change any, as neither of the options is used in the finished page. The part just doesn't exist inside the final page. I've just discovered, that since I included the if-else, the template modification (done via Template Modification System) does not work any more as there is a compiler error. It says, it may is caused by another template modifying the same place, but as there is no other modification and it works, as soon as I remove the branch, something must be wrong there...
     
  8. katsulynx

    katsulynx Well-Known Member

    Managed to solve the problem myself. The correct code has to look like this:
    PHP:
        <style type="text/css">
            <
    xen:if is="{$visitor.customFields.11}">
            
    html, .level_1, .secondaryContent h3, .sectionHeaders, .application_container h1, .location_headline  {
                    
    backgroundurl({$visitor.customFields.11}) repeat fixed center !important;
                }
                .
    nodeIcon {  
                    
    backgroundurl(@imagePath/xenforo/kitsunebi_IMG/f_icon.png), url({$visitor.customFields.11}) fixed !important;
                }
          
            <
    xen:else />
            
    html, .level_1, .secondaryContent h3, .sectionHeaders, .application_container h1, .location_headline  {
                    
    backgroundurl(@imagePath/xenforo/kitsunebi_IMG/background.pngrepeat fixed center !important;
                }
                .
    nodeIcon {  
                    
    backgroundurl(@imagePath/xenforo/kitsunebi_IMG/f_icon.png), url(@imagePath/xenforo/kitsunebi_IMG/background.pngfixed !important;
                }
            </
    xen:if>
          
    </
    style>
    Maybe the documentation needs a bit of an update regarding the correct use of elseif and else. I thought it needed to be used like in normal code, e.g.:
    PHP:
    <xen:if [...]>
    </
    xen:if>
    <
    xen:elseif [...]>
    </
    xen:elseif>
    <
    xen:else>
    </
    xen:else>
    but it actually has to be used like this:
    PHP:
    <xen:if [...]>
    XYZ //called if first condition is true
    <xen:elseif [...] />
    XYZ //called when first isn't but second is
    <xen:else />
    XYZ //called if neither first nor second is correct
    </xen:if>
     
  9. Brogan

    Brogan XenForo Moderator Staff Member

  10. katsulynx

    katsulynx Well-Known Member

    Thanks, I have just found that wonderful resource of you at my search for inspiration on what to create next (y) Maybe you should link to that ressource in the FAQ?
     
  11. Brogan

    Brogan XenForo Moderator Staff Member

  12. katsulynx

    katsulynx Well-Known Member

    *coughs* I, of course, knew that and just wanted to test your knowledge :oops:
     
  13. katsulynx

    katsulynx Well-Known Member

    When I call @html.background, I'll get the full background css-property returned, e.g.:
    Code:
    background: #fff url(xyz.png);
    is there a way to get that without the "background:" for example or only the url? I want to stack another image over the background-image here.
     

Share This Page