0

I have a matrix field called {gallery} it has a column with 2 checkboxes - public and private

I would like to show only the items marked private but would also like an optional message if there are no private items. This code does not work:

{gallery} {if publicprivate =="private"} {if no_results}
       No rows available
   {/if}  
 <li><img src="{imageupload}"/></li> {/if}  
{/gallery}                        

3 Answers 3

1

Matrix supports a search param, so I'm pretty sure this should do it:

{gallery search:publicprivate="=private"}
    {if no_results}no private items available{/if}
    <li><img src="{imageupload}" /></li>
{/gallery}

EDIT - alternatively you could try something more like this:

{if gallery:total_rows search:publicprivate="=private" > 0}
no private items available
{/if}
 {gallery search:publicprivate="=private"}
    <li><img src="{imageupload}" /></li>
{/gallery}
3
  • {gallery search:publicprivate="private"}... will show only the private images if they are available but I cannot output any text between the two tags
    – user579984
    May 5, 2013 at 21:19
  • Ah. I found a thread that deals with something similar - using a query instead of the matrix fieldtype tag pair in order to get the no_results side of things: expressionengine.stackexchange.com/questions/6494/… May 6, 2013 at 1:11
  • +1 a million times - saved me a (s/butt/boat/g)load of trouble
    – phatskat
    Jun 5, 2013 at 19:32
0

You could try this too:

{gallery}
    {if public}Public content here{/if}
    {if private}Private content here{/if}
{/gallery}
3
  • I can output the content ok - it is the ability to output a message if the private content does not exist that is causing me the problem
    – user579984
    May 5, 2013 at 22:29
  • Where is the private/public content? Is it a row in the matrix field? If it is what is the field name and what kind of content is it? May 7, 2013 at 14:44
  • The matrix columns contain a title, imageupload (safecracker field) and publicprivate checkbox - public, private
    – user579984
    May 7, 2013 at 19:02
0

This answer does not quite solve my initial problem but it does allow me to show if a private gallery contains any photos:

I added 2 columns - public and private each with a P&T checkbox. In 'private' I set this to

1 : private

I created each gallery separately using

{gallery search:public="public"}<li><img src="{imageupload}"></li>{/gallery}

Then, in the private gallery I added the following text to my title:

Private Gallery: ({gallery:sum col="private"}) images.

By having the private checkbox equalling a number I am able to output the number of images that the private gallery is showing by counting the 'private' column checks. This lets users know whether there are any images in this hidden gallery before they send a request to view the gallery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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