1

I'm using the flexslider to create a carousel of pictures and use channel entries to populate the list items (images) that the flexslider uses to create the carousel.

Now I want to add a link to a pdf on al those list items that I have in a matrix field in the channel and that works also but only for the first list item.

Anybody nows why this is?

<div class="flexslider">
    <ul class="slides">
        {exp:channel:entries channel="lr_press"}
            {if press_slider_switch != ""}
            {press_artikel}
            <li><a href="{press_document}" targat="_blank"><img src="{press_beeld}" alt="{title}" /></a></li>
            {/press_artikel}
            {/if}
        {/exp:channel:entries}
    </ul>
</div>
  • What kind of field is "press_slider_switch"? – Jean St-Amand Aug 12 '13 at 18:36
0

I suggestion - but I would recommend having the markup for the slider inside your entries loop - that way if no results are returned, absolutely no slider markup winds up in the page template. So like this:

{exp:channel:entries channel="lr_press"}
    {if count == "1"}
    <div class="flexslider">
        <ul class="slides">
    {/if}

    {exp:switchee variable="{press_slider_switch}" parse="inward"}
        {case value="on"}
             markup for ON items (so your matrix field, I believe)
        {/case}
        {case value="off"}
             markup for OFF items
        {/case}
    {/exp:switchee}     

    {if count == total_results}
        </ul>
    </div>
    {/if}
{/exp:channel:entries}

With regard to what's going on for each list item - if you describe in a bit more detail what "press_slider_switch" is - as a conditional wrapped around your list items, it can certainly have a big impact on what's generated for your slider - then I might be abel to assist further.

EDIT: Added switchee example to the markup above. Also - one thing you might consider is using Entry Type add-on in place of switch. It has the same effect, really, except that it would allow you to hide/show your matrix field only for the switch values for which it is relevant - more for user-friendliness for the editor than anything - not much different in terms of the data or templating.

| improve this answer | |
  • okaaay...never looked at it that way. Well first of all "press_slider_switch" is actually a P&T switch. To give some more info, in the back-end users can enter the following fields in the press channel: quote / image / document. The thing is that quote and image needs to be entered both or not because they belong together. To avoid creating complicated conditionals and fallbacks I thought I create a switch so the user can decide whether to use the quote and image and I only need to check whether the switch is set. That's why I approached it this way. But I'm a newb so... :D – claudio_101 Aug 12 '13 at 22:20
  • A P&T switch field wouldn't be blank though, right? It would always have a state of either on or off? I haven't used one in a while, so i can't remember the specifics of the field setup. But I would expect it not to be blank, and instead give you a yes/no, on/off state or something like that - which may be why your wrapping conditional isn't behaving as you expect. The other thing you can do is install Croxton's Switchee add-on to use early-parsed switch case matching for your conditional. Great for performance and simplicity. I've edited above to demonstrate a bit further. – Jean St-Amand Aug 13 '13 at 10:26
  • Hey Jean thx for your suggestion. I checked the PT switch value and the OFF value was blank, that's why used the empty string to compare. I followed your tip to use switchee and it did help so I guess it has to do with the parsing? Now I have to say that if I used a string value for ON and OFF my switchee didn't work but from the moment I used integer values 0 and 1 switchee did his work. Is this normal? – claudio_101 Aug 13 '13 at 14:53
  • It should work with any value you specify - even a string, as Switchee offers Regex matching as well. – Jean St-Amand Aug 13 '13 at 15:25
  • Strange do, juste did another test and switchee is still not evalutaing the PT switch value if set to string. But overall my problem is resolved, thanks for that Jean. I will do some more tests and if I can't find a solution I'll create a new post. Cheers and thx again! – claudio_101 Aug 14 '13 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.