Page 1 of 1

[SOLVED] Get Gallery field definition

Posted: Fri Jun 06, 2014 12:57 pm
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

Re: Get Gallery field definition

Posted: Fri Jun 06, 2014 1:06 pm
by psy
When above the custom fields foreach loop, you must identify the field directly, eg:

Code: Select all

{$image->fields.myfieldname.value}

Re: Get Gallery field definition

Posted: Fri Jun 06, 2014 2:55 pm
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.

Re: Get Gallery field definition

Posted: Fri Jun 06, 2014 7:25 pm
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.

Re: Get Gallery field definition

Posted: Fri Jun 06, 2014 9:20 pm
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.

Re: Get Gallery field definition

Posted: Sat Jun 07, 2014 10:17 am
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?

Re: Get Gallery field definition

Posted: Sat Jun 07, 2014 7:14 pm
by velden
You did check the 'Public' checkbox when creating the field definition? It needs to be public to be available in templates.

Re: Get Gallery field definition

Posted: Sun Jun 08, 2014 2:22 pm
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