VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: JyTy on August 10, 2012, 09:23:49 AM

Title: Custom fields layout - wrap in parent and add class?
Post by: JyTy on August 10, 2012, 09:23:49 AM
Hi,

I have a question about custom fields, right now their html gets generated like this:

<div class="product-field product-field-type-P"></div>
<div class="product-field product-field-type-S"></div>
<div class="product-field product-field-type-S"></div>
<div class="product-field product-field-type-S"></div>
<div class="product-field product-field-type-S"></div>

Is there a way to modify default_customfields.php so that custom fields that have a parent are wrapped in it (I would also like to add parent a unique class like its name)? Like this:

<div class="product-field product-field-type-P tv-specs">
    <div class="product-field product-field-type-S"></div>
    <div class="product-field product-field-type-S"></div>
    <div class="product-field product-field-type-S"></div>
    <div class="product-field product-field-type-S"></div>
</div>

I need this to solve the multilanguage problem of creating custom fields for more languages. I would create one group for each language and then hide them with css based on the language selected on the site.
Or has anyone came up with a better solution (I need to translate values too not just the field names, I have found a solution on the forum for that)

Thank you for all your help, really appreciated!
Have a nice day  8)
Title: Re: Custom fields layout - wrap in parent and add class?
Post by: Rocked on September 07, 2012, 21:25:12 PM
Hey I was looking for the same thing! :)  Figured out an answer so thought I'd share...  it's not perfect but it worked for me!  I never put descriptions under custom fields... so I am just using the descriptions box basically as my added class name -- all you have to do is type in "tv-specs" under description on the custom field and it will now add the class.

First... create a folder in your template directory like this (TEMPLATE NAME)/html/com_virtuemart/productdetails.  Then copy and paste the default_customfields.php over into it.  (You could just write over the original, but I prefer using overrides whenever possible.)

Next replace:

    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><b><?php echo JText::_($field->custom_title?></b></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<br/>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php

With:

<div class="product-field product-field-type-<?php echo $field->field_type; if (!empty($field->custom_field_desc)) {
  echo  " "; echo $field->custom_field_desc;}?>
">
<span class="product-fields-title" ><b><?php echo JText::_($field->custom_title?></b></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<br/>
<span class="product-field-display"><?php echo $field->display ?></span>
    </div><br />



Basically just echoed in the description as the class name & took the span displaying the description out ... & that's it!

(note if you bought a template -- like me... the template maker may have ignored the standard setup and the custom field code you are looking for might just be in default.php insteed of default_customfields.php)
Title: Re: Custom fields layout - wrap in parent and add class?
Post by: JyTy on September 08, 2012, 11:23:36 AM
Thank you for posting Rocked!
I think your approach should work for me just fine too  8)
Title: Re: Custom fields layout - wrap in parent and add class?
Post by: Rocked on September 10, 2012, 20:09:16 PM
No problem... I'd really like to see an extra input when editing custom fields with something like "Add Class" or something in the core.  It would be really handy! 
Title: Re: Custom fields layout - wrap in parent and add class?
Post by: be on November 08, 2012, 18:00:38 PM
Hi,
thanks, for something like this I have looked forward a lot of time.
I would also appreciate a own field for css-class or/and id.

Best regard