![]() |
how to do a conditional element on the postbit
I am involved in a pretty heavy rework of a template. I need to know how to do a conditional element on the postbit.
For example if there is data inserted into a custom field then it will display the title of the custom field and the data, but if there is no data added to the field the title will not be displayed. suggestions are appreciated. |
Code:
<if condition="$post['field#']">$post[field#]</if> |
Hi
You need to add something like this Code:
<if condition="$post['fieldX']"> Don't forget to end it too Code:
</if> Quote:
|
Usually you can get a sense of how to do a condition by looking at others in the same template. In your case, see this one:
HTML Code:
<if condition="$post['field2']"><div>$vbphrase[location_perm]: $post[field2]</div></if> HTML Code:
<if condition="$post['fieldx']"><div>Whatever: $post[fieldx]</div></if> |
Thanks for all the great advice, worked perfect.
--------------- Added [DATE]1234544458[/DATE] at [TIME]1234544458[/TIME] --------------- I think I phrased my question wrong though. I the custom fields I was able to do, but my issues lies with replies to the post. This is going to sound odd, but I am phrasing this to sound generic, and not necessarily the way it will be implemented on the board. A user posts a topic. Below the topic area it is totally empty. (no quick reply, no nothing) When a person replies to the topic, text will come up saying "replies to topic below", and obvioulsy, the reply will show. So it's just a matter of showing or hiding a chunk of text belwo the post, and above the replies, depending upon if there are replies. |
So you actually need something to show up under the first post in a thread?
|
I'm the middle man here between the designer so sorry about my slight confusion, but yes, that sounds like the ticket. I think it only needs to be text.
|
Just add something like this to the end of the postbit (or postbit_legacy) template (of course, format it correctly). Or use $template_hook[postbit_end] to add it:
HTML Code:
<if condition="$post['postid']==$thread['firstpostid']"> |
As always, thank you for your suggestions Lynne, and everybody else for that matter.
|
Hi guys,
I'm the guy working with Matt on this project :) What i was trying to figure out, was how to wrap the entire postbits block with a conditional check - if posts exist show postbits block, else show alternate block (or nothing). <if condition="$post==1> <div id="posts"> $postbit </div> <else/> <p>There are no posts in this category.</p> </if> Hope that clarifies :) Thanks again to everyone who took the time to reply - its much appreciated!! Cheers, Chris --------------- Added [DATE]1234590312[/DATE] at [TIME]1234590312[/TIME] --------------- To further clarify, i've uploaded a screenie of the layout i'm wokring on.. http://www.quicksnapper.com/connectr...load-details2/ Its the download details page in vbdynamic download manager. The postbits section is handled by vb and that is the updates block below the main image (i have pretty much stripped out all the usual forumy bits). Essentially we want the postbits (updates stream) block only to show if there are updates posted for that particular download. Cheers, Chris |
I'm not sure I understand. It sounds like you are simply using the postbit template, but not the showthread page, correct? So, do these posts even have post numbers? If so, then I suppose <if condition="$post[postcount] == '1'"> may be valid. I really can't tell because I'm not sure if you are using the same variable names at all for these posts.
|
Hi Lynne :)
Thanks for the reply and sorry for the confusion. I'll try explain in more detail. As mentioned before, we're essentially styling the download manager plugin, vbdynamix. Each download has a details page, where you can post updates in the form of posts and optionally allow users to reply etc. This part of the page seems is handled by vb. Since we've told VBD to use its own template, we can go crazy on it without worrying about messing up the main forum. My aim with this project is to get the downloads page to look un-forum-y as possible ;) This is what i have in the downloads details page (ADV_DYNA_SHOWENTRY): PHP Code:
In the postbit_legacy i have this: PHP Code:
PHP Code:
Cheers, Chris |
<if condition="$post[postcount] == '1'"> doesn't work? If not it's probably because $post[postcount] doesn't exist. You may have to spit out some variables in the templates in order to see exactly what is available and then determine what you want to use for your conditions.I am unfamiliar with vbdynamix so I really don't know that I can be of much help.
|
Hi Lynne,
I tried adding $post[postcount] into the ADV_DYNA_SHOWENTRY page and it didnt output anything. I then went on to add it to the postbit_legacy file and it now shows a 1,2,3 etc on each of the posts. So i'm guessing hte postcount option only works when inside of the postbit template. You mentioned spitting out some variables to see what is available. Could you elaborate? Thanks, Chris |
It sounds like you did what I was suggesting - putting something like $post[postcount] in the template to see what gets spit out. Unfortunately, I don't understand what this output page is you are talking about. If that variable works in the template, isn't that where you wanted to use it? You could do what you were saying in the postbit_legacty template by just wrapping it all in a condition, no?
HTML Code:
<if condition="$post[postcount] == '1'"> |
Your comment just sparked an idea! The postcount works when its inside of the postbit template, so if i move the stuff from the ADV_DYNA_SHOWENTRY template into the postbit_wrapper, the postcount should work and we would be golden. I'm gona give it a shot now and will post my findings once i've tested it..
Thanks again! Chris --------------- Added [DATE]1234597137[/DATE] at [TIME]1234597137[/TIME] --------------- close but no cigar :( it seems that postbit_wrapper is part of the postbit loop. The download that has no updates doesnt display the updates block, which is what we want, but then the download that has 5 updates displays the updates block, but only outputs one post. Any ideas? |
1 Attachment(s)
My goal has been to completely hide the updates block if no updates are available, but thinking more for consistency sake having the block always there isnt necessarily a bad thing. So now i am trying your suggestion, adding the check to the postbit_legacy template:
<if condition="$post[postcount] == '1'"> <li class="updates"> $template_hook[postbit_start] $template_hook[postbit_messagearea_start] <p class="update-date">$post[postdate]</p> <p class="update-message">$post[message]</p> <if condition="is_member_of($bbuserinfo, 6)"><a href="$post[editlink]" name="vB::QuickEdit::$post[postid]">Edit</a></if> $template_hook[postbit_end] </li> <else /> <li class="no-updates"> $template_hook[postbit_start] $template_hook[postbit_messagearea_start] There are no updates for this template. $template_hook[postbit_end] </li> </if> Based on the above, you would expect that the updates block will always be there and if update posts exist, they are displayed, else show a message saying that no updates are available. Unfortunately, what i've ended up with is just the updates heading on the page that doest have any updates (ie, no message saying no updates below the heading) and then on the page that does have updates i have the first update message displaying, but then the no updates messages outputted 3 times where the other updates should be. I know that probably doesnt make sense, so i've attached two images - one showing the download that doesnt have any posts and one of the download that does have posts. Thanks, Chris |
Looking at the code again, and studying the output of the postcount variable, i think i know why its outputting the way it is. It looks like the conditional is saying "if postcount is equal to 1", essentially targeting only the post whose post count is 1, ie the first post.
What do you think? Is it possible to tweak the conditional to say if posts exist, else... |
I'm a bit confused, but can't you just use the adlocation_firstpost template?
|
Hi Dismounted,
You'll have to excuse as this is my first vb project and am not yet 100% on par with how everything works. Would you mind elaborating on how you see it working? I recall seeing the adlocation_firspost variable in the postbit, but figured it was just a placeholder for a banner ad after the first post.. Cheers, Chris |
Actually the template is ad_showthread_firstpost (just checked :p). Don't let the name fool you, it is just a template that gets placed after the first postbit in a thread.
|
Hi Dismounted,
I'm still not sure how that can be used to conditionally wrap around the postbit to get the end result i am trying for.. How do u see that working? Thanks, Chris |
All times are GMT. The time now is 08:04 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|