Author Topic: Layout Position for Custom Field  (Read 1758 times)

Hawker

  • Beginner
  • *
  • Posts: 31
  • A beginner
Layout Position for Custom Field
« on: February 18, 2018, 15:55:22 pm »
When making a new Custom Field, there is a box asking for its Layout position:

Custom Fields>Custom Field>Layout position

I learned from a YouTube video that this (for my case) had to be set to <addtocart> (no spaces)

Usually in Joomla, 'Layout position' fields offer a drop-down menu to select from a list of available possibilities. My forum account here does not permit me to post to the 'Requested Features' board, but:

(i) Why is there no drop-down menu here?
(ii) Where can one find the list of available 'Layout position' options for VM3, showing the correct format of wording (e.g. <addtocart>) to type into the Layout position box?


Many thanks in advance guys!
VM v. 3.4.2
Joomla v. 3.9.3
PHP v. 7.2.1

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27426
  • Always on vacation
    • Jenkin Hill Internet
Re: Layout Position for Custom Field
« Reply #1 on: February 18, 2018, 18:31:14 pm »
The position required by the vast majority of custom field users will be 'addtocart' - ie the custom field is within the add to cart form so the value is available there to be shown when that product is added to cart.

In the file components/com_virtuemart/views/category/tmpl/default.php you can see alternative positions added by default, such as 'ontop' which is just above the vm-product-container div, or 'normal' just after the product full description. There is also 'onbot' and postions for 'related-products'.  The first three are rarely used, but the developer can add additional field positions should they be required in different positions simply by adding a code snippet to the default.php and using that file as a template override. eg: to add 'mynewposition'

<?php
   echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'mynewposition'));
?>

I suppose a selector could be used to display the positions but it would require addtocart to be the default and would rarely be used.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM 3.4.3.10057 on Joomla 3.9.8 PHP 7.0.33
Testing VM .3.6.0.10075 on Joomla 3.9.8

Hawker

  • Beginner
  • *
  • Posts: 31
  • A beginner
Re: Layout Position for Custom Field
« Reply #2 on: February 18, 2018, 21:35:56 pm »
Thank you jenkinhill, this solves things!  ;D

 
ontop- Just above the VM product container <div>
normal- Just after the product full description
onbot- Just below the VM product container <div>
addtocart- Within the 'Add to cart' form

 
VM v. 3.4.2
Joomla v. 3.9.3
PHP v. 7.2.1

joomlaperth

  • Beginner
  • *
  • Posts: 2
  • A beginner
Re: Layout Position for Custom Field
« Reply #3 on: April 14, 2019, 15:40:53 pm »
hi, can a custom field have two different positions (is this even possible with defining two separate CSS classes?

1) in category layout
2) product details page?

thanks in advance

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2158
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Layout Position for Custom Field
« Reply #4 on: April 14, 2019, 17:50:10 pm »
You can display a customfield at two different positions. But this needs some extra code in your category and productdetail template.
Jörgen @ Kreativ Fotografi
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

joomlaperth

  • Beginner
  • *
  • Posts: 2
  • A beginner
Re: Layout Position for Custom Field
« Reply #5 on: April 15, 2019, 05:03:31 am »
Hi mate, thanks for the reply, i am using latest version of joomla and virtuemart.


Joomla! 3.9.5
VirtueMart 3.4.2

what files exactly do i need to change and can you shed some light on it please? thanks

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3821
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Layout Position for Custom Field
« Reply #6 on: April 15, 2019, 14:18:14 pm »
A customfield position is rendered in product with code
Code: [Select]
   echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'ontop'));This render the customfiled in position 'ontop' using sublayouts/customfields.php
The defualt file isf YOURJOOMLA/components/com_virtuemart/sublayouts/customfields.php
and template override
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/customfields.php
If you want anohter render you can use for eg.
Code: [Select]
   echo shopFunctionsF::renderVmSubLayout('mycustomfieldrender',array('product'=>$this->product,'position'=>'ontop'));and add a copy of default in the template
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/mycustomfieldrender.php
and modify the code in this file