×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Call customfields into module

Call customfields into module 2 years 10 months ago #29141

  • Caseyz
  • Caseyz's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 2
Hello,
I was trying to call some of the extra fields ( such as the state-name) fields into a module override template. I've tried adding the :
<?php echo $hotspot->state-name; ?>
but this returns no results.
when i use:
<?php echo $hotspot->customfields; ?>
the entire string of extra fields is shown.
How would i call a single customfield to display?
-Thanks
Sorry if I'm a bit of a php newb.

Call customfields into module 2 years 10 months ago #29142

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 154
  • Thank you received: 1081
look at the view.html.php in views/hotspot/

there I do this:
$customFieldsModel = JModelLegacy::getInstance('Customfields', 'HotspotsModel');
$customFields = $customFieldsModel->getItems($hotspot->catid);
		// Make a new array that has the slug for key
		foreach ($customFields as $field)
		{
			$this->customFields[$field->slug] = $field;
		}
I load the config for the custom field for this category.

Then in the actually template I go through each custom field and if we have an entry, then I display it.
<?php if($this->hotspot->customfields && $this->customFields) : ?>
		<div class="hotspots-customfields">
			<h6><?php echo JText::_('COM_HOTSPOTS_CUSTOM_FIELDS'); ?></h6>
			<?php foreach($this->hotspot->customfields as $key => $customFields): ?>
				<?php if(isset($this->customFields[$key])) : ?>
					<dl class="dl-horizontal">
						<dt><?php echo JText::_($this->customFields[$key]->title); ?></dt>
						<dd><?php echo HotspotsHelperCustomfields::getTranslatedValue($this->customFields[$key], $customFields); ?></dd>
					</dl>
				<?php endif; ?>
			<?php endforeach; ?>
		</div>
	<?php endif; ?>

Btw, I'm currently working on refactoring the whole code and moving it to our library (this way we will be able to add custom fields to all our components). So with the next update you'll have to do some changes to your code. Just letting you know, so that you don't wonder when you update :)

Cheers,
Daniel

Call customfields into module 2 years 10 months ago #29143

  • Caseyz
  • Caseyz's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 2
Hello,
Thanks for the quick response and the heads-up about the future changes. However; I didn't see a "view.html.php" in the module? Do I need to alter this in the component in order to create the module override?
Maybe I forgot that detail. I am creating an override for "mod_hotspots_list", and I want specific custom fields to display in the list. the default template looks like:
<ul class="locationslist">
	<?php foreach($list as $hotspot) : ?>
		<?php $hotspot->hotspots_id = $hotspot->id; ?>
		<li>
			<a href="<?php echo HotspotsUtils::createLink($hotspot); ?>">
				<?php echo $hotspot->name; ?>
			</a>
            <div><b><?php echo $hotspot->town; ?></b></div>
            <div><?php echo $hotspot->description_small; ?></div>
            <div><?php echo $hotspot->customfields; ?></div>
		</li>
 
	<?php endforeach; ?>
</ul>

and I would like to display a couple of extra fields, specifically slugs "state-name" and "phone-number.

-Thanks again

Call customfields into module 2 years 10 months ago #29144

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 154
  • Thank you received: 1081
I'm talking about the component. The module doesn't have this code as when I wrote the module there were no custom fields.
You'll need to do the part from the view.html.php and after that you can do
<dd><?php echo HotspotsHelperCustomfields::getTranslatedValue($this->customFields[$key], $customFields); ?></dd>

Regards,
Daniel

Call customfields into module 2 years 10 months ago #29146

  • Caseyz
  • Caseyz's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 2
Hello,
I adjusted the view file and appended it from
$customFieldsModel = JModelLegacy::getInstance('Customfields', 'HotspotsModel');
to
$customFieldsModel = JModelLegacy::getInstance('Customfields', 'HotspotsModel');
		$customFields = $customFieldsModel->getItems($hotspot->catid);
		// Make a new array that has the slug for key
		foreach ($customFields as $field)
		{
			$this->customFields[$field->slug] = $field;
		}

but I'm still not sure how the module template file should look. The code you provided looks liek it should return an array. I'm would want to displaying specific fields. I tried pasting in that specific code you provided but it just broke the page.
Any hints would be helpful.
-Thanks again

Call customfields into module 2 years 10 months ago #29148

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 154
  • Thank you received: 1081
Okay, I just finished abstracting the core code into the library. Let us do the following - I'll add support for custom fields to the module and you can test the package (hopefully tomorrow).

Regards,
Daniel
  • Page:
  • 1
Time to create page: 0.087 seconds