Keyword

Add Custom Classes to Extra Fields

  • Jesse Dockett
  • Jesse Dockett's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #127850 by Jesse Dockett
Add Custom Classes to Extra Fields was created by Jesse Dockett
What we have is a site that provides content to the general public about literary magazines and books. The site makes money through ad revenue that is embedded in the site in a similar fashion to the reviews. What we are attempting to create is a method for an advertiser who has purchased a login to sign in the front end, create an item in k2, fill out all of the extra fields in the k2 item and have the content render for the genral public looking at the site with minimal to no formatting interaction from the staff of the site owner with the k2 item.

The fields that we are transitioning are quite extensive and can be seen here: npofficespace.com/print-magazine-listings/listing-questionnaire/

What we need to do is have slight variations in css from one displayed field (for the public viewer). EG street number and street name need to be on one line together while city, state, country, and zip need to be on another.

Basically, what we need is a way to add custom classes to the extra fields through extra fields manager so that the advertiser never sees the class and the end user never sees any unintended variation in the text input by an advertiser.

I was thinking we could do this through the alias, where a script would grab the alias from the SQL database when it pulls the field and then uses the alias as a class for the whole field. I'm just not sure how to grab that bit of info on the transfer. Any guidance on how to do this/does anyone know of a k2 extension that would allow custom classes for extra fields? I came up short while googling.

Thanks for reading and thanks for any help in advance!

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127851 by Lefteris
Replied by Lefteris on topic Re: Add Custom Classes to Extra Fields
Hi. The only way to do this is to use extra field aliases like this:
$item->extraFields->EXTRA_FIELD_ALIAS->value
$item->extraFields->EXTRA_FIELD_ALIAS->name

This way you can wrap any extra field to a container. Note that this applies to item page in front-end. Regarding the form fields you can make a template override to itemform.php and add a class name based on the field id. Both the id and the type of the field are available there:
$extraField->id
$extraField->type

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Jesse Dockett
  • Jesse Dockett's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #127852 by Jesse Dockett
Replied by Jesse Dockett on topic Re: Add Custom Classes to Extra Fields
Thanks for putting me on the right path Lefteris,

I took a slightly different route in the end, using the first word of the . For anyone else interested in doing this, just add:
Log in  or Create an account to join the conversation.

More
10 years 5 months ago #127853 by Lefteris
Replied by Lefteris on topic Re: Add Custom Classes to Extra Fields
Just remember to apply your changes to overrides and not to the core files. Otherwise you will lose them in the next update.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.