We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Checkboxes

Development and Programming

seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

This is the chunk for the “case_study” weblog that is being pulled.

<ul class="work">

                        {exp:weblog:entries weblog="case_study" limit="10" pageinate="bottom"}
            
                               {if count != "1"}<li class="divider"></li>{/if}

                <li class="work-col-ab-a">
                    <ul>
                        <li><a href="http://{client_url}" title="{title}" target="_blank" rel="noopener">{client_image}</a></li>
                                                {if case_study_yn == "Yes"}<li class="case"><a href="http://{url_title_path=work/case-study}" title="{title}: Case Study">Case Study</a></li>{/if}
                    </ul>
                </li>
                <li class="work-col-ab-b">
                    <ul>
                        <li><span>Client:</span>

                            <ul>
                                <li class="client"><a href="http://{client_url}" target="_blank" rel="noopener">{title}</a></li>
                            </ul>
                        </li>
                        <li><span>Services:</span>
                            <ul>
                                 {exp:php} ob_start(); {/exp:php}{development}{exp:php} if(strpos(ob_get_contents(), "Web Design")!==false): {/exp:php}<li><a href="http://www.re-volvemedia.com/services/development/web-design/">Web Design</a></li>{exp:php} endif; ob_end_clean(); {/exp:php}
                                 {exp:php} ob_start(); {/exp:php}{development}{exp:php} if(strpos(ob_get_contents(), "Web Design")!==false): {/exp:php}<li><a href="http://www.re-volvemedia.com/services/development/e-commerce/">E-Commerce</a></li>{exp:php} endif; ob_end_clean(); {/exp:php}
                            </ul>
                        </li>
                    </ul>
                </li>

Hope this is helpful.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Alright, i tested it on my end and you need to restructure the ob_end_clean() like this:

<?php ob_start(); ?>{checkboxes}<?php $str=ob_get_contents();ob_end_clean(); if(strpos($str, "three")!==false): ?><a href="http://www.re-volvemedia.com/services/development/web-design/">Web Design</a><?php endif; ?>

Also, I don’t know what the {exp:php} tag is, so that may or may not be breaking it?

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

That is a plug-in I just downloaded it is supposed to let you use PHP in templates that don’t that the option set for the template. When I set that option it caused the page to break. it adds “<?php” and “?>” to the beginning and end and allows you to run PHP code without having to give the permissions to the template.

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

Mark,

That worked perfectly. The {exp:php} tags did not work however, but for some reason when I tried giving PHP the permission to run it worked fine! 😊

Would this work?

{if count > 2} PHP Code with 3px fix for IE6 {if:else} PHP Code as is {/if}
       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

without any context i don’t see why it wouldn’t seth.

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

It does work I just have to figure out the logic to say:

If the count is above 2 use this code on all that go above 2.

What it is currently doing is applying it to all if it is above 2.

Edit:

I think the count is acting differently than normal. Normally when you use {if count > 2} anything after 2 would be displayed with the specified style, however with this it is counting the total number and then if it is greater than 2 it is applying the style to all displayed?

       
Michael Cage's avatar
Michael Cage
19 posts
18 years ago
Michael Cage's avatar Michael Cage

Love the extension … and everything you do.

I have it working for custom weblog fields, but I’m wondering if there is a way to use this for custom profile fields, as well? It’d make a project I’m working on become remarkably simple.

Thanks in advance for any thoughts.

Be well, Michael Cage

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

@Michael: Custom profile fields are a little different, but certainly possible if you’re up for a little tinkering. You’ll have to poke around in the /system/cp/ files and find the places to make changes as I’ve never really looked into this. On the surface though I can’t imagine it would be too difficult.

@Seth: I’m still a little confused. The tag isn’t a loop so there shouldn’t be any need (or possible way) to use the count. You simply call {field_name} and it prints out ALL the selected checkboxes. There’s no way to say something like {field_name}….{count}….{/field_name}. Can you explain how you’re using the count? My initial guess is that you’re seeing the count of the weblog entry the field is in and not the count of the checkboxes.

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

Sure,

I am trying to fix an IE6 bug and for some reason the from the third box down there is a 3px bump to the left and I have a special class that fixes that. So I was trying to use count to give that style to the items if they went above the second one.

So it would look like this.

<ul>
    <li>Item 1</li>
    <li>Item 1</li>
    <li class="threepx">Item 1</li>
    <li class="threepx">Item 1</li>
    <li class="threepx">Item 1</li>
</ul>
       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

can you show me the EE tags you’re using to create that list? In your previous example each li was printed explicitly, not in a loop so you could just apply the class directly to that <li>.

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

This is how it is currently set up:

<?php ob_start(); ?>{development}<?php $str=ob_get_contents();ob_end_clean(); if(strpos($str, "Web Design")!==false): ?><li><a href="http://www.re-volvemedia.com/services/development/web-design/">Web Design</a></li><?php endif; ?>

I then created a simple If statement like this:

{if count > 2}
     
     PHP line from above with added class

{if:else}

     PHP line from above as is

{/if}

When I used that it would count the total number and if the total number was greater than 2 it would add the class to all items displayed and vice versa.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Seth, sorry I’ve been so slow to get back to this. I think I’m beginning to understand though. The last bit of confusion is “what does {count} count?”

       
seth.aldridge's avatar
seth.aldridge
68 posts
18 years ago
seth.aldridge's avatar seth.aldridge

Mark,

Thanks for taking the time to keep looking into this.

I’m sure that I’m using it incorrectly, but in the docs this is what it says:

“You could use this to apply different styles to the first entry or have the last 5 entries out of 10 be formatted differently.” but it refers to entries rather than physical items.

I was trying to get {count} to count the total number displayed between the {if} conditionals. But that is not how it is used.

I’m not sure if that makes more sense.

Thanks, Seth

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

I see. The {count} tag displays the number of the entry being displayed. It has no bearing in regards to the fields within the entry. If you’re trying to get the number of items in a checkbox field, you may be best off using PHP. Something like this may work:

<?php

ob_start();
{checkbox_field_name separator="\\r"}
$data = preg_split('/[\r]+/', ob_get_contents());
ob_end_clean();

$count = count($data);

?>

Of course then it would be up to you to structure your field display into that code.

       
lithiumdave's avatar
lithiumdave
215 posts
18 years ago
lithiumdave's avatar lithiumdave

I must be missing something crucial here but I just can’t get the extension to output the chosen checkbox values from the weblog entry. I’ve called my checkbox custom field ‘sizes’, and the checkboxes appear in the entry form. I’ve also placed {sizes} in my template, within the weblog:entries tag - which incidentally is displaying all other custom field content. But nothing appears in the rendered page, just blank.

Am I missing something? Many thanks : )

       
1 2 3 4 5 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.