Page 1 of 2
[Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Mon Aug 09, 2010 2:56 pm
by kerryshamblin
I've combed through the forums and the documentation, and it appears that the only available order to display CompanyDirectory Custom Fields in the templates is alphabetically.
Does anyone know how to display one custom field at a time in a template, so that Custom Fields and standard fields can be rearranged at will?
Alternatively, does someone know a way to order the Field Definitions?
Thank you.
Re: Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 11, 2010 3:13 pm
by kerryshamblin
So, I'll add all the details of the system I'm working on, in hopes that someone who can will guide me toward a solution. I thought I was asking a general question, but maybe knowing all of this will inspire someone to reply.
CMS Version 1.8.1
CGExtensions 1.19.2
CGSimpleSmarty 1.4.5
CompanyDirectory 1.6.5
CustomContent 1.7.3
FrontEndUsers 1.12
I'm feverishly trying to learn about Smarty variables, as I suspect that I could do what I want to do if I knew how to work Smarty.
It seems there are "standard" fields that Company Directory collects, namely: address, contact_email, telephone, fax, details and website. Other "Custom Fields" can be created as Field Definitions and I see that those custom fields can be displayed in the template like this:
{if $customfieldscount gt 0}
{foreach from=$customfields item=customfield}
{$customfield->name}: {$customfield->value}
{/foreach}
{/if}
However, I'm not happy with the order of display of these custom fields. I can see in the database that each of these custom fields has an id and an item_order. I would like to either be able to order the customfields in the output, or better yet display each custom field where I want it in the template, interspersed with the "standard" fields in the form that the user sees.
I've literally spent days searching the forum for topics related to this, and I'm only posting because I haven't found anything. Any help or guidance would be greatly appreciated.
Re: Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 11, 2010 3:48 pm
by Rolf
Hey,
You can try using this in the top of your detail template:
Code: Select all
{if $customfieldscount gt 0}
{foreach from=$customfields item=customfield}
{capture assign=$customfield->name}{$customfield->value}{/capture}
{/foreach}
{/if}
This way you assign the fieldcontent to a string, in stead of displaying it
You can use for instance {$your_field_name} in your detail template on any place you want.
Hope this helps
Rolf :)
Re: Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 11, 2010 5:12 pm
by kerryshamblin
Thanks, Rolf.
I understand the theory of what you are suggesting, but I'm having trouble implementing. I've inserted the code you provided at the top of the detail template, but I'm having trouble with displaying the desired customfield->value in the template.
The Field Definitions in my CompanyDirectory have names like Host Organization and Academic Director. So, I'm trying to display the values of those fields using your suggestion and placing {$'Host Organization'} doesn't work nor does {$Host Organization}, and I've tried an array of other silly, stabbing-in-the-dark attempts.
Please forgive my lack of prowess in this department, and thank you so much for helping. If you could coddle me along any further, I would be grateful.
Re: Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 11, 2010 5:27 pm
by Rolf
Some additional information:
Create field definitions with names like
name or
some_name. No spaces! Use underscore instead.
In the template you can use these parameters as:
Code: Select all
{if $name}
<p>The name is {$name}</p>
{/if}
Code: Select all
{if $some_name}
<p>Search with Google for: <a href="http://www.google.com/search?q={$some_name}">{$some_name}</a></p>
{/if}
Hopes this made it more clear ;)
Regards, Rolf
ps.
In your case something like:
Code: Select all
<p>Name Host Organization: {$host_organization}</p>
And host_organization is here the name of the field definition.
Re: Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 11, 2010 6:07 pm
by kerryshamblin
Thanks, Rolf! Problem solved. Now on to the other problems...

Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Tue Aug 17, 2010 7:47 pm
by kerryshamblin
I'm now trying to apply this theory to the Summary Template. The code I'm working with looks like this:
Code: Select all
{if $customfieldscount gt 0}
{foreach from=$customfields item=customfield}
{capture assign=$customfield->name}{$customfield->value}{/capture}
{/foreach}
{/if}
{if isset($items)}
{foreach from=$items item=entry}
<div class="CompanyDirectoryItem">
<strong>{$entry->company_name}</strong><br />
{$City}, {$State}<br />
<a href="{$entry->detail_url}">Details</a>
{if $entry->website ne ''}
– <a href="{$entry->website}">Web Site</a>
{/if}
</div>
{/foreach}
As you can see, I inserted the same code Rolf suggested at the top of the template, and then called the custom fields by name, but they aren't showing up in the Summary. Any ideas?
Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 18, 2010 4:08 pm
by Rolf
kerryshamblin wrote:
I'm now trying to apply this theory to the Summary Template.
...but they aren't showing up in the Summary. Any ideas?
Uhm, I am not shure these fields are available in the summary view...

Thought I read a reply of Calguy somewhere that this wasn't the case.
grtz. Rolf
Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 18, 2010 5:29 pm
by Rolf
Hi kerryshamblin,
Searching for the post of Calguy I mentioned, which might not even excist

I found another, much better solution...!
Code: Select all
{$entry->customfieldsbyname.yourfieldname}
You can use this in both the summary, as detail templates.
Grtz. Rolf
Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Wed Aug 18, 2010 5:37 pm
by kerryshamblin
What an excellent solution! So simple. Thank you so much.
Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Fri Sep 17, 2010 7:06 pm
by jtcreate
Just want to thank you both. This post saved me SO much time and headache. Sending kudos and happiness your way on this lovely Friday afternoon. Enjoy your day!
Re: [Solved] Is it possible to order Field Definitions in CompanyDirectory?
Posted: Fri Sep 17, 2010 7:12 pm
by Rolf
jtcreate wrote:
Just want to thank you both. This post saved me SO much time and headache. Sending kudos and happiness your way on this lovely Friday afternoon. Enjoy your day!
Good to hear
I also created a new wiki page on this:
http://wiki.cmsmadesimple.org/index.php ... yDirectory
®
Re: [Solved] Is it possible to order Field Definitions in Co
Posted: Tue Jul 12, 2011 10:05 pm
by ACDS
I found your info on these pages most helpful. I am however a bit stuck. i am not a genius at coding to please please bear with me.
I have created a number of checkboxes under the Flied Definitions. I only want the checked boxes to show up. For some reason all of the Field Definitions are showing up once you call up the detail of a company on the front end.
Am I just daft?
Re: [Solved] Is it possible to order Field Definitions in Co
Posted: Wed Jul 13, 2011 11:43 am
by M@rtijn
No, you are not
In the details template there is are a couple lines that call all customfields, search for:
Code: Select all
{if $customfieldscount gt 0}
{foreach from=$customfields item=customfield}
{$customfield->name}: {$customfield->value}<br />
{/foreach}
{/if}
If you don't want all these custom checkboxes you'll have to call them all individually:
Code: Select all
{$entry->customfieldsbyname.Yourname}
Where 'Yourname' is the exact name you specified for you checkbox (Case-sensitive)
What you can also do, is to check if there is a value for a certain box and display it if answer is yes:
Code: Select all
{if $entry->customfieldsbyname.Yourname ne ''}
{$entry->customfieldsbyname.Yourname}
{/if}
Re: [Solved] Is it possible to order Field Definitions in Co
Posted: Wed Jul 13, 2011 1:09 pm
by ACDS
thank you so incredibly much M@rtijn!!!