Please help with Smarty in CompanyDirectory template

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

I've just read the Smarty manual, and I still don't grasp how to accomplish what I want to do. There are no posts that I can find that handle this.

I appreciate the help I got recently from Rolf on another post where I was attempting to order the custom fields in the CompanyDirectory detail template.

(Please forgive my lack of knowledge about how to encase code in a separate box, and feel free to let me know how its done.)

I put this code at the top of the template:

Code: Select all

{if $customfieldscount gt 0}
      {foreach from=$customfields item=customfield}
            {capture assign=$customfield->name}{$customfield->value}{/capture}
      {/foreach}
{/if}
and then displayed the Custom Fields by their name, as so:

Code: Select all

{if $Host_Organization ne ''}
<p><strong>Host Organization:</strong> {$Host_Organization}</p>
{/if}
Works great, thanks to Rolf! I'm trying to apply the same principle to the Add/Edit a Frontend Form Template in CompanyDirectory, but if I apply it directly, there are no input boxes created in the form, nor are my values present.

I started by putting the same bit of {foreach}{capture} code at the top of the template and trying several methods of getting the custom fields to show up. Here is a sample of code from the template:

Code: Select all

{$startform}

    <div class="row">
        <div class="prompt">{$nametext}:</div>
        <div class="input">{$inputname}</div>
    </div>

    <div class="row">
	<div class="prompt">Host Organization:</div>
	<div class="input">???</div>
    </div>
The first row is a "standard" field. The {$inputname} smarty tag is defined in action.fe_edit.php, and from my limited understanding, creates an input text field and fills in the variable if the Company ID is >0.

In the default template, the customfields are created using a tag that looks like {$customfield->input_box}, but that simply makes an empty box, and the values aren't filled in during the "Edit Company" mode.

I would like to know how to create and populate that custom field with Smarty. Anyone?

Thanks for reading this.


// Rolf : Added code tags
Last edited by kerryshamblin on Thu Mar 07, 2013 5:49 pm, edited 2 times in total.
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

By the way, I did read this: http://calguy1000.com/Blogs/12/60/basic ... kills.html, which was a great intro.

I'm running:

CMSMS 1.8.1
CompanyDirectory 1.6.5
CGSimpleSmarty 1.4.5
CGExtensions 1.19.2
FrontEndUsers 1.12
SelfRegistration 1.6.1
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Please help with Smarty in CompanyDirectory template

Post by Rolf »

Hello Kerryshamblin,

please try this and see if it works:

Code: Select all


{if $customfieldscount gt 0}
    {foreach from=$customfields item=customfield}
        {capture assign=$customfield->name}{$customfield->name}{/capture}
        {capture assign=foo}{$customfield->name}_input{/capture}
        {capture assign=$foo}{$customfield->input_box}{/capture}
    {/foreach}
{/if}

    <div class="row">
        <div class="prompt">{$field1}:</div>
        <div class="input">{$field1_input}</div>
    </div>
    <div class="row">
        <div class="prompt">{$Host_Organization}:</div>
        <div class="input">{$Host_Organization_input}</div>
    </div>
    <div class="row">
        <div class="prompt">{$field2}:</div>
        <div class="input">{$field2_input}</div>
    </div>

You still need to fill for field1 and field2 your names of course.

Hope this helps,

Rolf
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

Thanks, Rolf! It works like a charm. It helps me to learn how to manipulate Smarty, too. I really appreciate it. I think it's time for my donation to CMSMS now. Cheers!
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Please help with Smarty in CompanyDirectory template

Post by Rolf »

kerryshamblin wrote: Thanks, Rolf! It works like a charm. It helps me to learn how to manipulate Smarty, too. I really appreciate it.
Great, glad I could help.

You don't need to have the fieldname tag in the code of course.
The real names can directly in the template, like this:

Code: Select all

{if $customfieldscount gt 0}
    {foreach from=$customfields item=customfield}
        {capture assign=foo}{$customfield->name}_input{/capture}
        {capture assign=$foo}{$customfield->input_box}{/capture}
    {/foreach}
{/if}

    <div class="row">
        <div class="prompt">Field number 1:</div>
        <div class="input">{$field1_input}</div>
    </div>
    <div class="row">
        <div class="prompt">Host Organization:</div>
        <div class="input">{$Host_Organization_input}</div>
    </div>
    <div class="row">
        <div class="prompt">Field number 2:</div>
        <div class="input">{$field2_input}</div>
    </div>
kerryshamblin wrote: I think it's time for my donation to CMSMS now. Cheers!
Thanks!

You can also nominate CMSMS for the Packt Open Source Awards:
http://www.packtpub.com/open-source-awa ... source-cms
http://www.packtpub.com/open-source-awa ... ce-project
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: [SOLVED] Please help with Smarty in CompanyDirectory template

Post by Rolf »

kerryshamblin wrote: (Please forgive my lack of knowledge about how to encase code in a separate box, and feel free to let me know how its done.)
You can use the # button for this. It puts the code tags around the text.
I will change it for you in your first post!

Also created a Wiki page for the Company Directory module, with a link to this page.
http://wiki.cmsmadesimple.org/index.php ... yDirectory

Perhaps others might benifit from this thread.

Regards, Rolf  :)
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: [SOLVED] Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

Done and done! Thanks again, Rolf.
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: [SOLVED] Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

This was working until I changed the State_Province customfield to a dropdown instead of a text input. In the backend, I can edit the company and an actual dropdown shows up, but not in the frontend template. Is this a bug that I should report, or am I missing something?
kendo451

Re: [SOLVED] Please help with Smarty in CompanyDirectory template

Post by kendo451 »

There's a slightly easier way:

{assign var=$field->name value=$field->value} with achieve the same thing without calling a capture.
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: [SOLVED] Please help with Smarty in CompanyDirectory tem

Post by Rolf »

Company Directory, release 1.10+

Code: Select all

{$entry->customfieldsbyname.yourname}
Is changed in:

Code: Select all

{$entry->fields.yourname->value}
Hope this helps,

Rolf
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: [SOLVED] Please help with Smarty in CompanyDirectory tem

Post by kerryshamblin »

Thanks for posting that tip, Rolf, but I can't seem to get my add-edit-company form to generate the input boxes now that I've upgraded to 1.17. Lost Again!
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

Hello again. I have removed the [SOLVED] from this topic because since upgrading, my add/edit company template is no longer working.

I have a list of Field Definitions that I want to intersperse in the add/edit company template with the "standard" fields, and Rolf's solution above was great until I upgraded to 1.17. Now I've upgraded to 1.17.5. It still doesn't help me figure out how to generate input boxes for custom fields in the add/edit company template.

I have the system and all relevant modules at the latest version.

Any help would make my day a little better. Thank you!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Please help with Smarty in CompanyDirectory template

Post by Dr.CSS »

The call for the fields may have changed, add {get_template_vars} to the bottom of the template to see what the fields look like, default and custom ones...
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: Please help with Smarty in CompanyDirectory template

Post by kerryshamblin »

Thank you, Dr. CSS. Adding that to the bottom of the add/edit company template, the default fields all showed up on that output, but the only thing that pointed toward custom fields was this:

Code: Select all

customfields = Array (0)
customfieldscount = 0
Part of the special need is to have the field definitions interspersed with the default fields, rather than just in a clump at the end. There is nothing in the template that calls the custom fields as a group. Rolf helped out awhile back with the code I used (see above) but it stopped working after the upgrade.

I really appreciate your help.
inyerface
Forum Members
Forum Members
Posts: 191
Joined: Mon Nov 26, 2007 4:46 pm

Re: Please help with Smarty in CompanyDirectory template

Post by inyerface »

Did anyone find a solition for this? I'm getting the same results as kerryshamblin:

customfields = Array (0)
customfieldscount = 0

Although I have 4 created

CompanyDirectory 1.19.5
CMSMS 1.11.9
Post Reply

Return to “Modules/Add-Ons”