Page 1 of 2
Please help with Smarty in CompanyDirectory template
Posted: Fri Aug 13, 2010 5:52 pm
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
Re: Please help with Smarty in CompanyDirectory template
Posted: Fri Aug 13, 2010 6:14 pm
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
Re: Please help with Smarty in CompanyDirectory template
Posted: Fri Aug 13, 2010 11:07 pm
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
Re: Please help with Smarty in CompanyDirectory template
Posted: Fri Aug 13, 2010 11:57 pm
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!
Re: Please help with Smarty in CompanyDirectory template
Posted: Sat Aug 14, 2010 8:52 am
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
Re: [SOLVED] Please help with Smarty in CompanyDirectory template
Posted: Sat Aug 14, 2010 9:26 am
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
Re: [SOLVED] Please help with Smarty in CompanyDirectory template
Posted: Tue Aug 17, 2010 3:45 pm
by kerryshamblin
Done and done! Thanks again, Rolf.
Re: [SOLVED] Please help with Smarty in CompanyDirectory template
Posted: Thu Sep 30, 2010 1:57 pm
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?
Re: [SOLVED] Please help with Smarty in CompanyDirectory template
Posted: Tue Oct 12, 2010 9:15 pm
by kendo451
There's a slightly easier way:
{assign var=$field->name value=$field->value} with achieve the same thing without calling a capture.
Re: [SOLVED] Please help with Smarty in CompanyDirectory tem
Posted: Thu Oct 20, 2011 3:58 pm
by Rolf
Company Directory, release 1.10+
Code: Select all
{$entry->customfieldsbyname.yourname}
Is changed in:
Hope this helps,
Rolf
Re: [SOLVED] Please help with Smarty in CompanyDirectory tem
Posted: Tue Jan 29, 2013 9:44 pm
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!
Re: Please help with Smarty in CompanyDirectory template
Posted: Thu Mar 07, 2013 6:24 pm
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!
Re: Please help with Smarty in CompanyDirectory template
Posted: Thu Mar 07, 2013 7:25 pm
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...
Re: Please help with Smarty in CompanyDirectory template
Posted: Fri Mar 08, 2013 2:14 am
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.
Re: Please help with Smarty in CompanyDirectory template
Posted: Wed Oct 30, 2013 11:35 pm
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