CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Display specific custom field in template?
Pages: [1]

Author Topic: Display specific custom field in template?  (Read 1631 times)

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Display specific custom field in template?
October 28, 2009, 11:41:58 am
Is there a way to pull out the value of a specific custom field when creating a custom template?

Thanks!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Display specific custom field in template?
October 28, 2009, 11:51:07 am

yes, but u'll need to  do some additional work:

1. Implement a buildForm / pageRun hook (depending on what template) and expose that custom field to the smarty template.

2. Use that exposed variable in the template

another alternative might be to create a new api function which given an entity ID and custom fieldID returns the value of that custom field. Given this function, u can use the "crmAPI" smarty function

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Display specific custom field in template?
October 28, 2009, 12:54:45 pm
Thanks.  I'm not seeing how to access the template from the hook_civicrm_pageRun() hook.  The only argument provided to the function is $page, which has the following properties according to a print_r:

Code: [Select]
CRM_Event_Page_EventInfo Object
(
    [_name:protected] => CRM_Event_Page_EventInfo
    [_title:protected] => Event Information
    [_mode:protected] => null
    [_embedded:protected] =>
    [_print:protected] =>
    [_id] => 2
)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Display specific custom field in template?
October 28, 2009, 01:24:12 pm

u can use:

Code: [Select]
$page->assign( 'varName', $varValue );

in the template refer it to by:

Code: [Select]
{$varName}

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Display specific custom field in template?
October 28, 2009, 01:37:34 pm
Thanks.  Also, is there a way to add plugins to CiviCRM's Smarty instance without dumping them in the Smarty plugins dir in Core?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Display specific custom field in template?
October 28, 2009, 04:28:48 pm

probably, but i have not tried / experimented with it

Smarty has a plugin_dir include path and you can add your own custom path to it. We added the civicrm plugins directory that way

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Display specific custom field in template?
October 29, 2009, 11:02:45 am
For the future reference of others, here's a way to add a custom plugin directory without modifying any core code:

Code: [Select]
function yourmodule_civicrm_pageRun(&$page) {
$template = $page->getTemplate();
array_push($template->plugins_dir, 'path/to/custom/plugin/directory');
}


Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Display specific custom field in template?
October 29, 2009, 02:07:30 pm
That's cool - can you add this tip to the "Customizing Screens" section on the wiki?

Seems like you're doing some interesting customizations - would be great to get a quick overview of the project at some point :-) - on the Showcase board or perhaps a blog post if there's some customization techniques / code you can share with other developers.
Protect your investment in CiviCRM by  becoming a Member!

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Display specific custom field in template?
October 29, 2009, 02:21:48 pm
It's really not that exciting -- just a site that I'm building around someone else's excellent design, rather than trying to design around the software's default output.  It's also going to be maintained day-to-day by NGO staff who have low computer proficiency.

So, for instance, I need to display the event subtitle in a different font from the venue name and a different font than the description, and I don't trust the staff to consistently format those in a WYSIWYG editor, so I'm creating separate custom fields for them and have to pull each one separately and apply different markup to them.

Then we have a list of committee members, to be displayed in 4 columns, but the easiest way for the staff to input them is as a single chunk of text, one name per line.  I wrangled Smarty into splitting this up by line into a single array, but splitting the array into pieces and outputting them separately is something it can't do with the markup we need, unless I use a plugin.

I'm actually surprised some of these use cases don't come up more frequently.

EDIT: I've written this up briefly here -- don't know if it's in a good place.
« Last Edit: October 29, 2009, 02:45:29 pm by lentilsoup »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Display specific custom field in template?
October 29, 2009, 04:04:22 pm
The writeup is beautiful and in the right spot. Thx! We are embarking on a several release process to make all the markup in Civi much more theme-able / designer friendly. As this progresses, your input will be most appreciated!
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Display specific custom field in template?

This forum was archived on 2017-11-26.