View Full Version : display extra fields
dannyd
03-23-2009, 01:41 PM
I'd like to display extra fields in my template. How can I call certain fields to show up ? I tried the code below but no luck.
/**
* Get extra fields from DB
*/
$sql = "SELECT * FROM jos_hp_properties2 as p2".
"\n LEFT JOIN jos_hp_prop_ef AS ef ON p2.field = ef.id".
"\n WHERE p2.property = '".$f->id."'";
$database->setQuery($sql);
$extrafields = $database->loadObjectList();
foreach ($extrafields as $ef) {
if ($ef->name == "hp_squaremeters") {
$squaremeters = $ef->value;
} else if ($ef->name == "hp_bedrooms") {
$bedrooms = $ef->value;
}
}
dknight
03-24-2009, 06:50 PM
Which file are you using with those codes?
timothypsoulen
04-09-2009, 03:16 AM
I have a similar need to selectively show extra fields in the property detail page. Can I add something like the above code to the default.php property view or is there somewhere else to define these extra field variables so I can call them in the property view?
Thanks!
andrewdferguson
12-01-2009, 10:52 PM
Did anyone get a satifactory answer to this???
I need to do a price range, and so added an extra field as the upper price limit and want to grab this and display it after PRICE with the word "to" in between. I can get the "to" easily enough, of course, but trying to get the extra field to display is proving nigh on impossible. I I have tried every permeatation I can think of!! Driving me crazy! What the hell are extra fields called? do they have an HP_ added at the beginning of their names or something?
PLEASE help!
Thanks in advance.
Padder
12-05-2009, 06:02 AM
Hi,
There's a few ways to do that, I found using a switch the easiest to follow.
In HP1.0RC the file to change is components/com_hotproperty/views/properties/tmpl/property.php.
Comment out lines 40-51 inclusive, this is what you're removing:
<dl class="attributes">
<?php foreach ($this->extrafields as $extrafield) : ?>
<?php
$extrafield_value = MosetsHTML::_('hotproperty.content.extrafield', $extrafield, $this->row);
if (!empty($extrafield_value)) : ?>
<?php if (!$extrafield->hideCaption && !empty($extrafield->caption)) : ?>
<dt class="caption <?php echo $extrafield->name; ?>"><?php echo $this->escape($extrafield->iscore ? JText::_($extrafield->caption) : $extrafield->caption); ?></dt>
<?php endif; ?>
<dd class="value <?php echo $extrafield->name; ?>"><?php echo $extrafield_value; ?></dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
Replace with your own version of this code (this just uses example fieldnames, you'll need to have a 'case' for each of your own fieldnames that you are using from your database table):
<?php
foreach ($this->extrafields as $extrafield) :
$extrafield_value = MosetsHTML::_('hotproperty.content.extrafield', $extrafield, $this->row);
if (!empty($extrafield_value)) :
switch ($extrafield->name) {
case "type":
$itemcategory = $extrafield_value;
break;
case "quantity":
$itemquantity = $extrafield_value;
break;
case "intro_text":
$itemtext = $extrafield_value;
break;
case "yourfieldname":
$yourchosenvariablename = $extrafield_value;
break;
}
endif;
endforeach;
?>
Make sure there is a 'case' for each of your published fields. This routine just puts the hotproperty fields into standard variables, so you can then do what you want with them using normal php/html code, for example in the above code the description text (intro_text field in the database) is put into variable $itemtext, so I would display it like this:
<?php echo "<p class='description'>" . $itemtext . "</p>"; ?>
Basically once the hotproperty fields have been put into variables then you should find it easy to layout your page as you wish, using tables, divs, or whatever you're most comfortable with.
Hope that helps!
jessevandersteur
03-18-2010, 08:42 PM
Padder, thank you for the code above.
I know this is a 9 months old thread but I have a question to the post above. This solution is very awesome and works also with the new Hot Property 1.0.0. Makes configuring the lay-out easy.
Only problem with the code above is that the captions won't show, only the values. Does someone know a quick answer to that?
Padder
03-18-2010, 09:14 PM
Hi,
Glad you found it useful. I don't use the captions myself, they are written directly into my template as I'm only using one language.
Without testing this, I'd guess that something along these lines would get you the caption into a variable too (insert into each case you want a caption for):
case "yourfieldname":
$yourchosenvariablename = $extrafield_value;
$yourchosencaptionname = $extrafield->caption;
break;
Then you can use the caption in your own style of layout too.
If this doesn't work, then try things around that... the line that HP use to get the caption is:
<?php echo $this->escape($extrafield->iscore ? JText::_($extrafield->caption) : $extrafield->caption); ?>
so something based around that within the switch should work.
vBulletin® v3.8.6, Copyright ©2000-2023, Jelsoft Enterprises Ltd.