[SOLVED] Get Gallery field definition

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

[SOLVED] Get Gallery field definition

Post by nervino »

Hello, I've created a Field Definition (a checkbox with alias=pubblic_in_home_page) for the subgalleries, but I can't get its value in Gallery template.
I want to use the checkbox to show only checked sub-galleries in Home Page.

My gallery structure:

Code: Select all

- Gare
   - - First
   - - Second
   - - etc.
I call the module in this way:

Code: Select all

{Gallery dir="Gare" template="gallerytree2"}
In Gallerytree template, I'm using this Smarty code (suggested by Velden: http://forum.cmsmadesimple.org/viewtopi ... 93#p312793) to load Gallery images in the slideshow:

Code: Select all

{foreach from=$images item=image name=img}
<div class="{if $smarty.foreach.img.index > 0}hide{else}item backcolrhover{foreach from=$fields item=f key=fieldalias}{if $f.value} {$fieldalias}{/if}{/foreach}{/if}">
	<a class="fancybox" rel="gallery{$galleryid}" href="{root_url}/{$image->file}" title="">
		<div style="display:none" class="galtitle">
			{$image->title}<br />{$gallerycomment}
		</div>
		<div class="hoverlinks">
			<img src="/images/magcircle.png" class="mag" title="apri">
		</div>
		{if $smarty.foreach.img.index == 0}
			<img src="{root_url}/{$image->thumb|escape:'url'|replace:'%2F':'/'}" alt="" />
		{/if}
		</a>
		{if $smarty.foreach.img.index == 0}
			<div class="caption">
				{$gallerytitle}
			</div>
		{/if}
	</div>
	{*assign var='g_prevdepth' value=$image->depth*}
{/foreach}
I've added:

Code: Select all

{if $fields.pubblic_in_home_page.value eq '1'}pubblic_in_home_page is ONE
{else}pubblic_in_home_page is ZERO{/if}
before the above foreach loop, but I can't get the field.

Any ideas?

Thank you
Last edited by nervino on Sun Jun 08, 2014 2:23 pm, edited 1 time in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Get Gallery field definition

Post by psy »

When above the custom fields foreach loop, you must identify the field directly, eg:

Code: Select all

{$image->fields.myfieldname.value}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3492
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Get Gallery field definition

Post by velden »

psy wrote:When above the custom fields foreach loop, you must identify the field directly, eg:

Code: Select all

{$image->fields.myfieldname.value}
And below.

The foreach loop is 'created' conditionally so it's not sure it does exist. And I would not rely on a variable $fields outside the loop.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Get Gallery field definition

Post by nervino »

I tried to output
{$image->fields.pubblic_in_home_page.value}
before, inside and below the foreach loop but I can't find that variable anywhere.

I also tried to put just before and after the {foreach from=$images item=image name=img} loop:

Code: Select all

{$image->fields|print_r}
that outputs= Array ( ) 1 
and

Code: Select all

{$fields|print_r}
that outputs= Array ( ) 1 
Being this field related to the category and not to images themselves, may it be in another array..?

Another strange thing is that the cover image set for a gallery is not used.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3492
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Get Gallery field definition

Post by velden »

Being this field related to the category and not to images themselves, may it be in another array..?
Do you mean 'Gallery'?

You probably need to implement your logic in the gallerytree2 template.

The 'gallerytemplate' only loops through images of a sub gallery NOT the galleries itself.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Get Gallery field definition

Post by nervino »

Yes, I meant "gallery", sorry.
Hence, in gallerytree2 template can I retreive my field value? In which array I have to seek for it?
I didn't understand how Gallery module works and how I can get a Gallery-related custom field value.

From module help:
Gallery-related fields can be called directly in the gallerytemplate with {$fields.your_field_alias.name} and {$fields.your_field_alias.value}. You could also create a foreach loop on {$fields}.
but it does not work for me. Sure, I'm doing something wrong but I don't know what is it.

However, my goal is to let users to choose which gallery has to be published in home page; for this reason I thought I could use a custom checkbox field.

But maybe is there another, better, way to achieve this?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3492
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Get Gallery field definition

Post by velden »

You did check the 'Public' checkbox when creating the field definition? It needs to be public to be available in templates.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Get Gallery field definition

Post by nervino »

AARRGHH! It wasn't!
I only checked if the field was selected in the gallery but I didn't check the field itself...

I beg your pardon.

Thank you
Post Reply

Return to “Modules/Add-Ons”