xF2 Template Modification Make Cover/Banner As Postbit Custom Background

eLeonore

Active member
Registered
Joined
Oct 21, 2021
Messages
39
Points
28

Reputation:

Preview Desktop :
Screenshot_2021-10-25-14-20-32-509_com.android.chrome.jpg


Preview Mobile :
Screenshot_2021-10-25-14-25-20-735_com.android.chrome.jpg



Profile Preview :
IMG_20211025_142711.jpg



Requirements :
Addons : [tl] Profile Cover 3.0.0


Step 1 :
Go to Admin CP > Appearance > Templates > Search: message_macros

And Search This Code :
Code:
<xf:macro name="user_info"
    arg-user="!"
    arg-fallbackName="">

Put This Below :
Code:
<xf:if is="{$user.ProfileCover}">
<div class="postbit_background" style="background-image: url({$user.ProfileCover.cover_url});"></div>
    </xf:if>


Step 2 :
Go to Admin CP > Appearance > Templates > Search: extra.less

And add this css
Code:
.message-name, .message-userExtras, .message-userDetails {
position:relative;
}

.postbit_background {
    opacity: .20;
    position: absolute;
    border-radius: 4px 0px 0px 0px;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    background-position: center;
    background-size: cover !important;
}

And this css for handle in mobile view
Code:
@media (max-width: 650px) {
.postbit_background {
    height: 60px !important;
    }

or this css if you want to hide on mobile device :
Code:
@media (max-width: 650px) {
.postbit_background {
display: none;
}
}
 

MEGAHERZ

Collaborate
Collaborate
Registered
Joined
Mar 16, 2019
Messages
50
Points
38

Reputation:

Deleted

eLeonore

Active member
Registered
Joined
Oct 21, 2021
Messages
39
Points
28

Reputation:

lazarote

web enthusiastic
Collaborate
Registered
Joined
Jun 24, 2019
Messages
141
Points
53

Reputation:

There is a way to do this with Xenforo Default Banner System?
 

lazarote

web enthusiastic
Collaborate
Registered
Joined
Jun 24, 2019
Messages
141
Points
53

Reputation:

Change this code:

PHP:
<xf:if is="{$user.ProfileCover}">
<div class="postbit_background" style="background-image: url({$user.ProfileCover.cover_url});"></div>
    </xf:if>

for this one:

PHP:
<div class="postbit_background" style="background-image: url({$user.Profile.getBannerUrl($size)});"></div>
 

lazarote

web enthusiastic
Collaborate
Registered
Joined
Jun 24, 2019
Messages
141
Points
53

Reputation:

Change this code:

PHP:
<xf:if is="{$user.ProfileCover}">
<div class="postbit_background" style="background-image: url({$user.ProfileCover.cover_url});"></div>
    </xf:if>

for this one:

PHP:
<div class="postbit_background" style="background-image: url({$user.Profile.getBannerUrl($size)});"></div>
lazaroteI was having a problem in the console, i will do a tutorial to show how to fix it :)
 

lazarote

web enthusiastic
Collaborate
Registered
Joined
Jun 24, 2019
Messages
141
Points
53

Reputation:

I'm getting a console error every time someone views a topic that has a reply from a guest (that's what i think)

ErrorException: Template error: [E_USER_WARNING] Cannot call method getBannerUrl on a non-object (NULL) src/XF/Template/Templater.php:1153

Code:
Stack trace
#0 [internal function]: XF\Template\Templater->handleTemplateError(512, '[E_USER_WARNING...', '/www/wwwroot/un...', 1153, Array)
#1 src/XF/Template/Templater.php(1153): trigger_error('Cannot call met...', 512)
#2 internal_data/code_cache/templates/l2/s11/public/message_macros.php(16): XF\Template\Templater->method(NULL, 'getBannerUrl', Array)
#3 src/XF/Template/Templater.php(801): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, NULL)
#4 internal_data/code_cache/templates/l2/s11/public/post_macros.php(25): XF\Template\Templater->callMacro('message_macros', 'user_info', Array, Array)
#5 src/XF/Template/Templater.php(964): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#6 src/XF/Template/Templater.php(900): XF\Template\Templater->renderExtensionInternal('user_cell', Array, Array, Object(XF\Template\ExtensionSet))
#7 internal_data/code_cache/templates/l2/s11/public/post_macros.php(147): XF\Template\Templater->renderExtension('user_cell', Array, Object(XF\Template\ExtensionSet))
#8 src/XF/Template/Templater.php(964): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#9 src/XF/Template/Templater.php(900): XF\Template\Templater->renderExtensionInternal('full_body', Array, Array, Object(XF\Template\ExtensionSet))
#10 internal_data/code_cache/templates/l2/s11/public/post_macros.php(179): XF\Template\Templater->renderExtension('full_body', Array, Object(XF\Template\ExtensionSet))
#11 src/XF/Template/Templater.php(801): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#12 internal_data/code_cache/templates/l2/s11/public/thread_view.php(889): XF\Template\Templater->callMacro('post_macros', 'post', Array, Array)
#13 src/XF/Template/Templater.php(1628): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#14 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('thread_view', Array)
#15 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#16 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Html->renderView('XF:Thread\\View', 'public:thread_v...', Array)
#17 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#18 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#19 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#20 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#21 src/XF.php(488): XF\App->run()
#22 index.php(20): XF::runApp('XF\\Pub\\App')
#23 {main}

Code:
Request state
array(4) {
  ["url"] => string(12) "/temas/1083/"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

I tried to change my code to:

PHP:
<xf:if is="{{ $xf.visitor.Profile.banner_date ? 'profileBannerContainer--withBanner' : '' }} AND !$xf.visitor.isMemberOf(1)}}">   
<div class="postbit_background" style="background-image: url({$user.Profile.getBannerUrl($size)});"></div>
</xf:if>

But the error still :/
 

eLeonore

Active member
Registered
Joined
Oct 21, 2021
Messages
39
Points
28

Reputation:

I'm getting a console error every time someone views a topic that has a reply from a guest (that's what i think)

ErrorException: Template error: [E_USER_WARNING] Cannot call method getBannerUrl on a non-object (NULL) src/XF/Template/Templater.php:1153

Code:
Stack trace
#0 [internal function]: XF\Template\Templater->handleTemplateError(512, '[E_USER_WARNING...', '/www/wwwroot/un...', 1153, Array)
#1 src/XF/Template/Templater.php(1153): trigger_error('Cannot call met...', 512)
#2 internal_data/code_cache/templates/l2/s11/public/message_macros.php(16): XF\Template\Templater->method(NULL, 'getBannerUrl', Array)
#3 src/XF/Template/Templater.php(801): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, NULL)
#4 internal_data/code_cache/templates/l2/s11/public/post_macros.php(25): XF\Template\Templater->callMacro('message_macros', 'user_info', Array, Array)
#5 src/XF/Template/Templater.php(964): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#6 src/XF/Template/Templater.php(900): XF\Template\Templater->renderExtensionInternal('user_cell', Array, Array, Object(XF\Template\ExtensionSet))
#7 internal_data/code_cache/templates/l2/s11/public/post_macros.php(147): XF\Template\Templater->renderExtension('user_cell', Array, Object(XF\Template\ExtensionSet))
#8 src/XF/Template/Templater.php(964): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#9 src/XF/Template/Templater.php(900): XF\Template\Templater->renderExtensionInternal('full_body', Array, Array, Object(XF\Template\ExtensionSet))
#10 internal_data/code_cache/templates/l2/s11/public/post_macros.php(179): XF\Template\Templater->renderExtension('full_body', Array, Object(XF\Template\ExtensionSet))
#11 src/XF/Template/Templater.php(801): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#12 internal_data/code_cache/templates/l2/s11/public/thread_view.php(889): XF\Template\Templater->callMacro('post_macros', 'post', Array, Array)
#13 src/XF/Template/Templater.php(1628): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, Object(XF\Template\ExtensionSet))
#14 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('thread_view', Array)
#15 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#16 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Html->renderView('XF:Thread\\View', 'public:thread_v...', Array)
#17 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#18 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#19 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#20 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#21 src/XF.php(488): XF\App->run()
#22 index.php(20): XF::runApp('XF\\Pub\\App')
#23 {main}

Code:
Request state
array(4) {
  ["url"] => string(12) "/temas/1083/"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

I tried to change my code to:

PHP:
<xf:if is="{{ $xf.visitor.Profile.banner_date ? 'profileBannerContainer--withBanner' : '' }} AND !$xf.visitor.isMemberOf(1)}}">  
<div class="postbit_background" style="background-image: url({$user.Profile.getBannerUrl($size)});"></div>
</xf:if>

But the error still :/
lazarote
Code:
<xf:if is="{{$user.isMemberOf(3)}}">
    <xf:profilebanner user="$user" size="m" class="postbit_background"/>
    </xf:if>
 

lazarote

web enthusiastic
Collaborate
Registered
Joined
Jun 24, 2019
Messages
141
Points
53

Reputation:

Code:
<xf:if is="{{$user.isMemberOf(3)}}">
    <xf:profilebanner user="$user" size="m" class="postbit_background"/>
    </xf:if>
eLeonoreThe problem happens when the user don't have a banner even if he has the permission to upload one
 
Top