XF 1.2 Standard Value for Custom Fields

Lukas W.

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?
 
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.
 
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.
 
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...
 
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  {
                background: url({$visitor.customFields.11}) repeat fixed center !important;
            }
            .nodeIcon {  
                background: url(@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  {
                background: url(@imagePath/xenforo/kitsunebi_IMG/background.png) repeat fixed center !important;
            }
            .nodeIcon {  
                background: url(@imagePath/xenforo/kitsunebi_IMG/f_icon.png), url(@imagePath/xenforo/kitsunebi_IMG/background.png) fixed !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>
 
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?
 
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.
 
Back
Top Bottom