Page 1 of 1

[solved] Help with customizing template for EventManager

Posted: Fri Jun 21, 2013 8:27 am
by qwalk
Hi.

I have been starting to use EventManager to create shows for a theater. I love the module and the way templating works with a Summary page, and a Detail page. It is exactly what I need. :)

Well I have been starting to customize the Summary and Detail templates, and I am done with the Summary template. I do have a question about the Detail template page.

You see, I have created some custom fields, and I need to call these custom fields separately, and not all of them at once.

I have created 4 custom fields:
- An image field, it's basically a thumbnail for the summary page (at the summary page you are able to see all the shows at once, with a small picture)
- Another image field, this is for the details page, a bigger picture
- A textarea field (this is an info-box on each detail page)
- A text field (here you should be able to put in a link to where you can buy tickets) (Yes I am not using any of the registration features at all!)

These fields works great, But the only problem is that I need to be able to call them separately from the details page, because right now in the Detail page Both Images are shown, I don't need the first summary image. Also I need to make a custom CSS style for the info-box, and I need to wrap the buy ticket link around a banner I've made.

My custom fields have the following aliases:
- pic-for-summary (type: image)
- pic-for-details (type: image)
- info-box (type: text-area)
- ticket-link (type: text)

How can I call them in the following code, one by one? I've tried {$entry->fields.field-alias->value} as the documentation says in the top, But it doesn't work at all, nothing is shown. At the top of the template this is commented, but I don't know if this is for the custom fields, or not:

Code: Select all

{$entry->fields : an array of extra fields
			If you have an extra field with the alias "place", use :
			{$entry->fields.place->value}

		NOTE : sometimes, the extrafields values are arrays, so use {$entry->fields.place|print_r} to see what is available


Here is an example from the default detail template:

Code: Select all

{* Extra fields *}
{if isset($entry->fields)}
	{foreach from=$entry->fields item='oneval' key='key'}
		<h4>{$oneval->name}</h4>
		<div>
			{if $oneval->type eq 'image' and $oneval->value neq ''}
				<img src="{$oneval->file_url}" style="max-width: 200px" />
			{elseif $oneval->type eq 'checkboxes' and $oneval->value neq ''}
				<ul>
					{foreach from=$oneval->value item='onecheckbox'}
						<li>{$onecheckbox}</li>
					{/foreach}
				</ul>
			{elseif $oneval->value neq ''}
				{$oneval->value}
			{else}
				<p>No value for {$oneval->name}</p>
			{/if}
		</div>
		<br /><br />

		{* Uncomment to display all the info for the current field : *}
		{*
			{$key} : {$oneval|print_r}<br /><br />
		*}
	{/foreach}
{/if}


So, how do I call every custom field one by one, so I can wrap them around <div>'s and style them? :)

Re: Help with customizing template for EventManager

Posted: Fri Jun 21, 2013 11:55 am
by Jo Morg
qwalk wrote:I've tried {$entry->fields.field-alias->value} as the documentation says in the top, But it doesn't work at all, nothing is shown.
How are you calling the field exactly? It should work except if you actually use characters other than the alphanumeric plus the underscore on the field alias, IIRC.
Meaning:

Code: Select all

$entry->fields.my_place->value # this should work
$entry->fields.my-place->value # this shouldn't work
$entry->fields.my place->value # this won't work

Re: Help with customizing template for EventManager

Posted: Fri Jun 21, 2013 12:50 pm
by qwalk
Jo Morg wrote:

Code: Select all

$entry->fields.my_place->value # this should work
 
That worked perfect!

I didn't realize that, because when creating the custom fields, it auto-generates an alias with "-" and not "_". I changed all my smarty alias'es to _ and called them as you wrote, and that works perfect! Thank you very much.

Re: Help with customizing template for EventManager

Posted: Fri Jun 21, 2013 1:41 pm
by qwalk
Oh, and another thing. Is it possible to only show the values of the custom fields, if they have been entered in the event?

If for example an event has been crated, but the image for the details page has not been uploaded yet, is there a way to check if the field has a value, and then only call the field if there is a value?

Right now my template looks like this:

Code: Select all

<h1>{$entry->name}</h1> // this is the title of the event

<img src="uploads/{$entry->fields.pic_to_details->value}" /> // img of the show

<div class="details">
 {$entry->description}    // event description
</div>

<div class="info-box">
  {$entry->fields.info_box->value}    // an extra info box
</div>

<a href="{$entry->fields.link_to_tickets->value}" target="_blank">
 <img src="uploads/images/gfx/ticket-banner.png">    // banner link to tickets
</a>

If for example the link to tickets field has not been entered, the banner will still be shown and there will be no link. I want only the banner to be shown if the event manager has entered a ticket link.

Re: Help with customizing template for EventManager

Posted: Mon Jun 24, 2013 5:59 am
by qwalk
qwalk wrote:Oh, and another thing. Is it possible to only show the values of the custom fields, if they have been entered in the event?

If for example an event has been crated, but the image for the details page has not been uploaded yet, is there a way to check if the field has a value, and then only call the field if there is a value?

Right now my template looks like this:

Code: Select all

<h1>{$entry->name}</h1> // this is the title of the event

<img src="uploads/{$entry->fields.pic_to_details->value}" /> // img of the show

<div class="details">
 {$entry->description}    // event description
</div>

<div class="info-box">
  {$entry->fields.info_box->value}    // an extra info box
</div>

<a href="{$entry->fields.link_to_tickets->value}" target="_blank">
 <img src="uploads/images/gfx/ticket-banner.png">    // banner link to tickets
</a>

If for example the link to tickets field has not been entered, the banner will still be shown and there will be no link. I want only the banner to be shown if the event manager has entered a ticket link.

Any help to this ^ please? :)

Re: Help with customizing template for EventManager

Posted: Mon Jun 24, 2013 11:04 am
by Jo Morg
qwalk wrote:Oh, and another thing. Is it possible to only show the values of the custom fields, if they have been entered in the event?
Depending on what the template gives you, one of the following should work:

Code: Select all

{if isset($entry->fields.link_to_tickets->value)}
<a href="{$entry->fields.link_to_tickets->value}" target="_blank">
 <img src="uploads/images/gfx/ticket-banner.png">    // banner link to tickets
</a>
{/if}
#--------------------------------------------------------------#
{if !empty($entry->fields.link_to_tickets->value)}
<a href="{$entry->fields.link_to_tickets->value}" target="_blank">
 <img src="uploads/images/gfx/ticket-banner.png">    // banner link to tickets
</a>
{/if}
#--------------------------------------------------------------#
{if $entry->fields.link_to_tickets->value != ''}
<a href="{$entry->fields.link_to_tickets->value}" target="_blank">
 <img src="uploads/images/gfx/ticket-banner.png">    // banner link to tickets
</a>
{/if}
This is BASIC Smarty syntax... a little search would have given you the answers